我有一个脚本来发送带有嵌入式图像和html正文的电子邮件,但是当我尝试发送其他文件时,它们被覆盖,这是我的perl代码
push @parts,
Email::MIME->create(
attributes => {
content_type => $CtypeB,
encoding => $EncodingB,
charset => $CharsetB,
},
body => $BodyB,
),
;
push @parts,
Email::MIME->create(
header_str=> [
'Content-ID' => $Content_ID,
],
attributes => {
content_type => $CtypeF,
encoding => $EncodingF,
'Content-Disposition' => $ContentD,
filename=> $FilenameF,
file => $FileF,
},
body => io($BodyF)->binary->all,
);
Email::MIME->create(
header_str => [
To => $Para,
From => $De,
Subject => $Asunto,
Cc => $Cc,
Bcc => $Bcc
],
attributes => {
content_type =>$CtypeH
},
parts => [@parts]
),
我假设是按安排创建的电子邮件:: MIME的元素可以通过推入来容纳,但是当我通过添加几个文件发送邮件时,它被覆盖,也就是说,它发送了最后一个附加的文件,任何想法或关于我在做什么错的建议?,谢谢。
您可以像这样附加多个文件:
use strict;
use warnings;
use Email::MIME;
my @parts;
push @parts, Email::MIME->create(
attributes => {
content_type => 'application/octet-stream',
disposition => 'attachment',
encoding => 'base64',
name => 'foobar.bin',
},
body => "\1\2\3\4\5\6\7",
);
push @parts, Email::MIME->create(
attributes => {
content_type => 'text/html',
disposition => 'attachment',
encoding => 'quoted-printable',
charset => 'UTF-8',
name => 'foobar.html',
},
body_str => "<!DOCTYPE html><title>foo bar</title><p>foo</p><p>bar</p>",
);
my $message = Email::MIME->create(
header_str => [
To => '[email protected]',
From => '[email protected]',
Subject => 'foo bar',
],
parts => \@parts,
);
print $message->as_string;
这将产生以下消息:
To: [email protected]
From: [email protected]
Subject: foo bar
Date: Mon, 9 Dec 2019 21:16:43 -0800
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="15759550030.CE8DFF428.4203"
--15759550030.CE8DFF428.4203
Date: Mon, 9 Dec 2019 21:16:43 -0800
MIME-Version: 1.0
Content-Type: application/octet-stream; name="foobar.bin"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
AQIDBAUGBw==
--15759550030.CE8DFF428.4203
Date: Mon, 9 Dec 2019 21:16:43 -0800
MIME-Version: 1.0
Content-Type: text/html; charset="UTF-8"; name="foobar.html"
Content-Disposition: attachment
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html><title>foo bar</title><p>foo</p><p>bar</p>=
--15759550030.CE8DFF428.4203--