<< 2008년 6월 15일 (일) | | 2008년 6월 17일 (화) >>

[perl] 메일 발송 클라이언트

먼저 메일 발송을 위해서는 많이 쓰는 라이브러리인 Email-Date-Format-1.002과 MIME-Lite-3.021를 설치한 다음 발송 perl 스크립트를 작성하시면 됩니다.

1. Email-Date-Format 설치

다운 사이트 : http://search.cpan.org/dist/Email-Date-Format/
>perl Makefile.PL
>make
>make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM"
"-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/basic...........ok
1/3 skipped: test only useful in US/Eastern, -0400, not +0900
t/pod-coverage....skipped
all skipped: Test::Pod::Coverage 1.08 required for testing POD coverage
t/pod.............skipped
all skipped: Test::Pod 1.14 required for testing POD
All tests successful, 2 tests and 1 subtest skipped.
Files=3, Tests=3, 0 wallclock secs ( 0.13 cusr + 0.05 csys = 0.18 CPU)
>make install
Perl 설치 디렉토리인 /opt/perl_32/lib/site_perl/5.8.8 여기에 설치됨

2. MIME-Lite 설치

다운 사이트 : http://search.cpan.org/dist/MIME-Lite/
>perl Makefile.PL
>make
>make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM"
"-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/addrs...........ok
t/data............ok
t/head............ok
t/parts...........ok
t/pod-coverage....skipped
all skipped: Test::Pod::Coverage 1.08 required for testing POD coverage
t/pod.............skipped
all skipped: Test::Pod 1.14 required for testing POD
t/types...........#
#Interaction with MIME::Types has not been tested
#as it doesn't seem to be present.
t/types...........ok
t/verify..........ok
All tests successful, 2 tests skipped.
Files=8, Tests=43, 0 wallclock secs ( 0.52 cusr + 0.16 csys = 0.68 CPU)
>make install

Perl 설치 디렉토리인 /opt/perl_32/lib/site_perl/5.8.8 여기에 설치됨

3. 메일 발송 클라이언트
#!/usr/bin/perl

use MIME::Lite;
use Net::SMTP;

### Adjust sender, recipient and your SMTP mailhost
my $from_address = 'pepsi@mimul.com';
my $to_address = 'pepsi@paran.com';
my $mail_host = 'mimul.com';

### Adjust subject and body message
my $subject = '메일 테스트 ...';
my $message_body = "파일이 하나 첨부되었삼";

### Adjust the filenames
my $my_file_path = 'MIME-Lite-3.021.tar.gz';
my $my_file_zip = 'MIME-Lite-3.021.tar.gz';

### Create the multipart container
my $msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";

### Add the text message part
$msg->attach (
Type => 'TEXT',
Data => $message_body
) or die "Error adding the text message part: $!\n";

### Add the ZIP file
$msg->attach (
Type => 'application/zip',
Path => $my_file_path,
Filename => $my_file_zip,
Disposition => 'attachment'
) or die "Error adding $my_file_path: $!\n";

### Send the Message
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;