関数単位だけど書いて残しておこう。
$attach には作成したHTML形式のデータを格納
sub sendmail {
my( $mailto, $mailfrom, $subject, $body ) = @_;
open( MAIL, "| $sendmail -f $mailfrom -t" );
local $attach = "";
local $boundary = "-*-*-*-*-*-*-*-*-Boundary_" . time . "_" . $$;
### サブジェクトを jis にして、MIME エンコード
$subject = mimeencode( $subject );
### 添付するデータを、base64 でエンコード
$attach = &bodyencode($body, "b64");
$attach .= &benflush("b64");
#本文
local $message = "添付ファイルを開いて確認してください。";
&jcode'convert(*message,'jis');
########################## メールの組み上げ
### 全体のヘッダ
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: Multipart/Mixed; boundary=\"$boundary\"\n";
print MAIL "Content-Transfer-Encoding:Base64\n";
print MAIL "From: $mailfrom\n";
print MAIL "To: $mailto\n";
print MAIL "Subject: $subject\n";
### メール本文のパート
print MAIL "--$boundary\n";
print MAIL "Content-Type: text/plain; charset=\"ISO-2022-JP\"\n";
print MAIL "\n";
print MAIL "$message\n";
### 添付ファイルのパート
print MAIL "--$boundary\n";
print MAIL "Content-Type: application/octet-stream; name=\"entry.html\"\n";
print MAIL "Content-Transfer-Encoding: base64\n";
print MAIL "Content-Disposition: attachment; filename=\"entry.html\"\n";
print MAIL "\n";
print MAIL "$attach\n";
print MAIL "\n";
### マルチパートのおわり。
print MAIL "--$boundary" . "--\n";
close MAIL;
}
コメントする