继 上篇 使用 perl 发带中文标题的邮件后,又研究了下发带附件的。
基本差别不大,主要是那个 Content-type 要变一下。那个 boundary 可以自己随便写,和后面的统一就行了。
my $title = encode_base64("标题", ""); my $body = encode_base64("邮件正文"); my $attach = encode_base64("附件内容"); my $filename = encode('MIME-B', decode('utf8', "文件中文.txt")) open(MAIL, '|/usr/sbin/sendmail -t'); print MAIL "From: test\@abs.com\r\n"; print MAIL "To: test\@abs.com\r\n"; print MAIL "Subject: =?UTF-8?B?$title?=\r\n"; print MAIL "MIME-Version: 1.0\r\n"; # print MAIL "Content-type: text/plain; charset=utf-8\r\n"; print MAIL <<EOF; Content-Type: multipart/mixed; boundary=\"FFFFFFFFKKKKKK\" --FFFFFFFFKKKKKK Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 $body --FFFFFFFFKKKKKK Content-Type: application/octet-stream Content-Disposition: attachment; filename=$filename.csv Content-Transfer-Encoding: base64 $attach --FFFFFFFFKKKKKK-- EOF close(MAIL);
Related posts: