HTML形式にレポートや申込み内容をまとめ添付してメールで送る処理(Perl)

| コメント(0)

関数単位だけど書いて残しておこう。
$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;

}

コメントする

Profile

Name:someiyoshino Home:Suginami Tokyo HP1:www.someiyoshino.biz HP2:www.seoby.biz Blog:www.someiyoshino.biz/blog Mail:info@someiyoshino.biz

2010年5月

            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

ウェブページ