Top/Devel/Perl/Net-SMTP

Net-SMTP の変更点はてなブックマーク

  • 追加された行はこの色です。
  • 削除された行はこの色です。
  • Devel/Perl/Net-SMTP へ行く。

SMTPサーバーを使ってメールを送る。
#code(perl,nonumber,nooutline){{
#!/usr/bin/perl -w

use POSIX qw(locale_h strftime);
use Net::SMTP;

my $sender  = 'foo@example.com';        # メールアドレス
my $server  = 'mail.example.com';       # SMTPサーバー
my $user    = 'foo';                    # ユーザーID
my $passwd  = 'bar';                    # パスワード

my $from    = 'info@example.com';       # FROM
my $to      = $ARGV[0];                 # TO
my $subject = $ARGV[1];                 # SUBJECT


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"

*参考
-[[Net::SMTP>http://www.perldoc.com/perl5.6.1/lib/Net/SMTP.html]]

*Amazon
#amazon(4873111269,left)
#amazon(4873111676,left)
#amazon(4797320656,left)
差分 一覧