[英]Send multiple files using Email :: MIME in perl?
我有一個腳本來發送帶有嵌入圖像和 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 => 'you@example.com',
From => 'me@example.com',
Subject => 'foo bar',
],
parts => \@parts,
);
print $message->as_string;
這會產生以下消息:
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--
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.