Arrays 在perl中使用Email::MIME发送多个文件?
我有一个脚本来发送带有嵌入图像和html正文的电子邮件,但是当我尝试发送其他文件时,它们会被覆盖,这是我的perl代码Arrays 在perl中使用Email::MIME发送多个文件?,arrays,perl,email,email-attachments,mime,Arrays,Perl,Email,Email Attachments,Mime,我有一个脚本来发送带有嵌入图像和html正文的电子邮件,但是当我尝试发送其他文件时,它们会被覆盖,这是我的perl代码 push @parts, Email::MIME->create( attributes => { content_type => $CtypeB, encoding => $EncodingB, charset => $Cha
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的元素,在安排中创建的这些元素可以使用push进行调整,但是,当我通过添加几个文件发送邮件时,它会被覆盖,也就是说,它会发送最后一个附加的文件,关于我做错了什么有什么想法或建议吗?谢谢。您可以像这样附加多个文件:
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 => 'you@example.com',
From => 'me@example.com',
Subject => 'foo bar',
],
parts => \@parts,
);
print $message->as_string;
使用严格;
使用警告;
使用Email::MIME;
我的@parts;
推送@parts,电子邮件::MIME->create(
属性=>{
内容类型=>'应用程序/八位字节流',
处置=>“附件”,
encoding=>base64,
name=>foobar.bin',
},
正文=>“\1\2\3\4\5\6\7”,
);
推送@parts,电子邮件::MIME->create(
属性=>{
内容类型=>'text/html',
处置=>“附件”,
encoding=>quoted printable',
字符集=>'UTF-8',
name=>foobar.html',
},
body_str=>“foo barfoobar”,
);
my$message=电子邮件::MIME->创建(
标题_str=>[
To=>'you@example.com',
From=>'me@example.com',
主题=>'foo-bar',
],
零件=>\@零件,
);
打印$message->as_字符串;
这将产生以下消息:
To: you@example.com
From: me@example.com
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--
至:you@example.com
发件人:me@example.com
主题:富吧
日期:2019年12月9日星期一21:16:43-0800
MIME版本:1.0
内容传输编码:7bit
内容类型:多部分/混合;边界=“15759550030.CE8DFF428.4203”
--15759550030.CE8DFF428.4203
日期:2019年12月9日星期一21:16:43-0800
MIME版本:1.0
内容类型:应用程序/八位字节流;name=“foobar.bin”
内容传输编码:base64
内容配置:附件
AQIDBAUGBw==
--15759550030.CE8DFF428.4203
日期:2019年12月9日星期一21:16:43-0800
MIME版本:1.0
内容类型:text/html;charset=“UTF-8”;name=“foobar.html”
内容配置:附件
内容传输编码:引用可打印
foo-barfoobar=
--15759550030.CE8DFF428.4203--
提示:使用\@parts
而不是[@parts]
可以避免不必要的复制。我不知道返回最终创建时要做什么;这可能是问题所在吗?除此之外,它看起来还可以。你能想出一个简短的可运行脚本来演示你的问题吗?这比使用更简单。