Perl 包含纯文本部分、html部分和附件的电子邮件
我正在尝试编写一个小Perl脚本,用于发送带有附件的纯文本/html电子邮件:Perl 包含纯文本部分、html部分和附件的电子邮件,perl,email,mime,html-email,email-attachments,Perl,Email,Mime,Html Email,Email Attachments,我正在尝试编写一个小Perl脚本,用于发送带有附件的纯文本/html电子邮件: use Encode(); use MIME::Entity(); my $msg = MIME::Entity->build( From => '"' . Encode::encode( 'MIME-Header', 'Any User' ) . '" <any.user@example.test>', To
use Encode();
use MIME::Entity();
my $msg = MIME::Entity->build(
From => '"' . Encode::encode( 'MIME-Header', 'Any User' ) . '" <any.user@example.test>',
To => '"' . Encode::encode( 'MIME-Header', 'Some User' ) . '" <some.user@example.test>',
Subject => Encode::encode( 'MIME-Header', 'Multipart alternative with attachments' ),
Type => 'multipart/alternative',
);
my $plain = $msg->attach(
Type => 'text/plain; charset=UTF-8',
Data => [ "*Multipart alternative with attachments*\n\nHere comes the plain text." ],
);
my $fancy = $msg->attach( Type => 'multipart/related' );
$fancy->attach(
Type => 'text/html; charset=UTF-8',
Data => [ "<html>\n\t<body>\n\t\t<h1>Multipart alternative with attachments</h1>\n\t\t<p>Here comes the fancy text.</p>\n\t</body>\n</html>" ],
);
$fancy->attach(
Type => 'text/plain; charset=UTF-8',
Disposition => 'attachment',
Filename => 'test.txt',
Data => [ "*Multipart alternative with attachments*\n\nHere comes the attachment." ],
);
使用Encode();
使用MIME::Entity();
my$msg=MIME::Entity->build(
From=>“”。Encode::Encode('MIME Header','Any User')。”,将正确显示纯版本和html版本。在Mozilla Thunderbird 11.0.1中,将不显示纯版本,而是显示简化的html版本
我的逻辑有错误还是Thunderbird失败了?您不需要$fancy
,将所有内容添加到$msg
标题最好是base64
或引用的可打印的
。它更简单
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
已过时。将来,请使用IETF网站查找RFC文本;顶部附近显示了相关的RFC。
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: base64
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable