Net-SMTP
SMTPサーバーを使ってメールを送る。
|
use POSIX qw(locale_h strftime);
use Net::SMTP;
my $sender = 'foo@example.com'; my $server = 'mail.example.com'; my $user = 'foo'; my $passwd = 'bar';
my $from = 'info@example.com'; my $to = $ARGV[0]; my $subject = $ARGV[1];
my $string = join('', <STDIN>);
setlocale(LC_TIME, 'C');
my $date = strftime('%a, %d %b %Y %T %z', localtime());
my $smtp = Net::SMTP->new($server, Timeout => 10);
$smtp->auth($user, $passwd) or die 'AUTHENTICATION ERROR';
$smtp->mail($sender) or die 'SENDER ERROR';
$smtp->to($to) or die 'RECIPIENT ERROR';
$smtp->data() or die 'SEND ERROR';
$smtp->datasend("From: $from\n") or die 'SEND ERROR';
$smtp->datasend("To: $to\n") or die 'SEND ERROR';
$smtp->datasend("Date: $date\n") or die 'SEND ERROR';
$smtp->datasend("Subject: $subject\n") or die 'SEND ERROR';
$smtp->datasend("\n") or die 'SEND ERROR';
$smtp->datasend("$string\n") or die 'SEND ERROR';
$smtp->dataend() or die 'SEND ERROR';
$smtp->quit;
|
使用方法
echo "this is test" | ./mail.pl hoge@example.net "test"
参考
Amazon