[root]# cpan Net::SMTP
・プログラム
#!/usr/bin/perl
##################################
# Net::SMTP(日本語文字化け回避)
##################################
use strict;
use warnings;
use Net::SMTP;
use Encode qw( decode encode );
my $host = 'mail.example.com';
my $from = 'foo@example.com';
my $to = 'bar@example.com';
# SMTP サーバーへの接続を確立
my $ns_obj = Net::SMTP->new(
Host => $host,
Hello => $host,
Timeout => 60, # デフォルト 120秒
);
# 送信元
$ns_obj->mail( $from );
# 送信先
$ns_obj->to( $to );
# 件名
my $subject = "件名";
$subject = encode( 'MIME-Header-ISO_2022_JP', decode( 'utf8', $subject ) );
# 本文
my $message = <<"EOD";
本文
本文
EOD
# メッセージ開始
$ns_obj->data();
$ns_obj->datasend( "From: $from\n" );
$ns_obj->datasend( "To: $to\n" );
$ns_obj->datasend( "Subject: $subject\n" );
# Content-Type: text/plain; charset=utf-8; で文字化け回避
$ns_obj->datasend( "Content-Type: text/plain; charset=utf-8;\n" );
$ns_obj->datasend( "Content-Transfer-Encoding: 8bit;\n" );
$ns_obj->datasend( $message );
# メッセージ終了
$ns_obj->dataend();
# 接続を切断
$ns_obj->quit;