包含 2 个多部分的电子邮件显示为一个
Email with 2 multiparts shows as one
我想弄清楚为什么我的多部分电子邮件全部显示为一个:
我用来为我的电子邮件创建 2 "parts" 的代码是:
use Email::MIME;
use Email::Address::XS;
use Email::Sender::Simple qw(sendmail);
# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
},
body_str => "Hello there é!",
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
}
),
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "inline",
charset => "UTF-8",
},
body_str => "Hello there éíó!",
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
}
)
);
my $email = Email::MIME->create(
header_str => [
From => 'andy@mysite.org',
To => [ 'Name <andy@foo.com>' ],
Subject => "foo"
]
);
$email->parts_set( \@parts );
print $email->as_string;
sendmail($email->as_string);
邮件已发送,结果如下:
Delivered-To: andy@foo.com
Received: by 10.223.130.5 with SMTP id 5csp329339wrb;
Thu, 11 Jan 2018 01:09:17 -0800 (PST)
X-Google-Smtp-Source: ACJfBotkcH6W0rsnQMkLx9pPqbt1rUgKaC9ShvWLQbn6u8muQbVnCjTCZRmf0d5RzegqW4AGpFHP
X-Received: by 10.28.92.146 with SMTP id q140mr474098wmb.5.1515661757887;
Thu, 11 Jan 2018 01:09:17 -0800 (PST)
Return-Path: <andy@mysite.org>
From: andy@mysite.org
To: Name <andy@foo.com>
Subject: foo
Date: Thu, 11 Jan 2018 09:09:17 +0000
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="15156617570.82fd1E.6414"
Message-Id: <E1eZYrN-0001fT-Hp@admin.myserver.org>
--15156617570.82fd1E.6414
Date: Thu, 11 Jan 2018 09:09:17 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello there =C3=A9!
--15156617570.82fd1E.6414
Date: Thu, 11 Jan 2018 09:09:17 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello there =C3=A9=C3=AD=C3=B3!
--15156617570.82fd1E.6414--
我可以看到分裂 "parts",但出于某种原因他们一起出现了?
更新::我以为我已经解决了这个问题 - 每个 @part
我有 2 个 attributes => { }
值,这导致 content_type 默认为 text/plain。所以我现在有:
my @parts = (
Email::MIME->create(
body_str => "Hello there <b>é!</b>",
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/plain",
disposition => "inline",
}
),
Email::MIME->create(
body_str => "Hello there <b>éíó!</b>",
attributes => {
content_type => "text/html",
disposition => "inline",
charset => "UTF-8",
encoding => 'quoted-printable',
}
)
);
...电子邮件显示为:
From: andy@mysite.org
To: Name <andy@foo.com>
Subject: foo
Date: Thu, 11 Jan 2018 09:45:21 +0000
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="15156639210.d5dF6bf.14583"
--15156639210.d5dF6bf.14583
Date: Thu, 11 Jan 2018 09:45:21 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hello there <b>=C3=A9!</b>
--15156639210.d5dF6bf.14583
Date: Thu, 11 Jan 2018 09:45:21 +0000
MIME-Version: 1.0
Content-Type: text/html; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hello there <b>=C3=A9=C3=AD=C3=B3!</b>
--15156639210.d5dF6bf.14583--
...但它仍然同时显示纯文本和 HTML 部分。奇怪的是,如果我在其中一些周围放置 标签,我会得到我期望的结果:
...但它只是并排显示它们:/
我不确定问题是什么,但我可以尝试打开其中发生的事情。因此,您定义的部分适用于不同的内容类型和传输编码,例如附件等。因此,当您使用边界时,它可以区分具有不同内容和编码的这些部分,以便在收到时可以正确解释。我假设您认为它将消息拆分为多个部分并分别发送?
我认为您误解了什么是多部分电子邮件。多部分电子邮件是由许多部分组成的单个电子邮件。每个部分可以是另一封电子邮件或另一个文件的内容。
您创建了一封电子邮件,其中包含许多其他电子邮件。
如果您想发送单独的电子邮件,那么您需要...好吧...发送单独的电子邮件:-)
更新: 好的,所以这里的术语是错误的。 OP 实际上并不希望由多个部分组成的电子邮件是单独的电子邮件,他希望单独的部分在他的电子邮件客户端中单独显示。在对他的代码稍作调整后,创建的电子邮件看起来是正确的 - 但 Gmail(出于某种原因)同时显示两个部分(一个纯文本和另一个 HTML)。
我通过比较一封我知道按预期工作的电子邮件与我的电子邮件终于解决了这个问题。
我发出的电子邮件有:
Content-Type: multipart/mixed; boundary="_----------=xxxxx"
但是工作人员有:
Content-Type: multipart/alternative; boundary="_----------=xxxxx"
果然,看到multipart/mixed,现在可以正常工作了:
$email->content_type_set( 'multipart/alternative' );
我想弄清楚为什么我的多部分电子邮件全部显示为一个:
我用来为我的电子邮件创建 2 "parts" 的代码是:
use Email::MIME;
use Email::Address::XS;
use Email::Sender::Simple qw(sendmail);
# multipart message
my @parts = (
Email::MIME->create(
attributes => {
content_type => "text/plain",
disposition => "inline",
charset => "UTF-8",
},
body_str => "Hello there é!",
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
}
),
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "inline",
charset => "UTF-8",
},
body_str => "Hello there éíó!",
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
}
)
);
my $email = Email::MIME->create(
header_str => [
From => 'andy@mysite.org',
To => [ 'Name <andy@foo.com>' ],
Subject => "foo"
]
);
$email->parts_set( \@parts );
print $email->as_string;
sendmail($email->as_string);
邮件已发送,结果如下:
Delivered-To: andy@foo.com
Received: by 10.223.130.5 with SMTP id 5csp329339wrb;
Thu, 11 Jan 2018 01:09:17 -0800 (PST)
X-Google-Smtp-Source: ACJfBotkcH6W0rsnQMkLx9pPqbt1rUgKaC9ShvWLQbn6u8muQbVnCjTCZRmf0d5RzegqW4AGpFHP
X-Received: by 10.28.92.146 with SMTP id q140mr474098wmb.5.1515661757887;
Thu, 11 Jan 2018 01:09:17 -0800 (PST)
Return-Path: <andy@mysite.org>
From: andy@mysite.org
To: Name <andy@foo.com>
Subject: foo
Date: Thu, 11 Jan 2018 09:09:17 +0000
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="15156617570.82fd1E.6414"
Message-Id: <E1eZYrN-0001fT-Hp@admin.myserver.org>
--15156617570.82fd1E.6414
Date: Thu, 11 Jan 2018 09:09:17 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello there =C3=A9!
--15156617570.82fd1E.6414
Date: Thu, 11 Jan 2018 09:09:17 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Hello there =C3=A9=C3=AD=C3=B3!
--15156617570.82fd1E.6414--
我可以看到分裂 "parts",但出于某种原因他们一起出现了?
更新::我以为我已经解决了这个问题 - 每个 @part
我有 2 个 attributes => { }
值,这导致 content_type 默认为 text/plain。所以我现在有:
my @parts = (
Email::MIME->create(
body_str => "Hello there <b>é!</b>",
attributes => {
encoding => 'quoted-printable',
charset => "UTF-8",
content_type => "text/plain",
disposition => "inline",
}
),
Email::MIME->create(
body_str => "Hello there <b>éíó!</b>",
attributes => {
content_type => "text/html",
disposition => "inline",
charset => "UTF-8",
encoding => 'quoted-printable',
}
)
);
...电子邮件显示为:
From: andy@mysite.org
To: Name <andy@foo.com>
Subject: foo
Date: Thu, 11 Jan 2018 09:45:21 +0000
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: multipart/mixed; boundary="15156639210.d5dF6bf.14583"
--15156639210.d5dF6bf.14583
Date: Thu, 11 Jan 2018 09:45:21 +0000
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hello there <b>=C3=A9!</b>
--15156639210.d5dF6bf.14583
Date: Thu, 11 Jan 2018 09:45:21 +0000
MIME-Version: 1.0
Content-Type: text/html; charset="UTF-8"
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Hello there <b>=C3=A9=C3=AD=C3=B3!</b>
--15156639210.d5dF6bf.14583--
...但它仍然同时显示纯文本和 HTML 部分。奇怪的是,如果我在其中一些周围放置 标签,我会得到我期望的结果:
...但它只是并排显示它们:/
我不确定问题是什么,但我可以尝试打开其中发生的事情。因此,您定义的部分适用于不同的内容类型和传输编码,例如附件等。因此,当您使用边界时,它可以区分具有不同内容和编码的这些部分,以便在收到时可以正确解释。我假设您认为它将消息拆分为多个部分并分别发送?
我认为您误解了什么是多部分电子邮件。多部分电子邮件是由许多部分组成的单个电子邮件。每个部分可以是另一封电子邮件或另一个文件的内容。
您创建了一封电子邮件,其中包含许多其他电子邮件。
如果您想发送单独的电子邮件,那么您需要...好吧...发送单独的电子邮件:-)
更新: 好的,所以这里的术语是错误的。 OP 实际上并不希望由多个部分组成的电子邮件是单独的电子邮件,他希望单独的部分在他的电子邮件客户端中单独显示。在对他的代码稍作调整后,创建的电子邮件看起来是正确的 - 但 Gmail(出于某种原因)同时显示两个部分(一个纯文本和另一个 HTML)。
我通过比较一封我知道按预期工作的电子邮件与我的电子邮件终于解决了这个问题。
我发出的电子邮件有:
Content-Type: multipart/mixed; boundary="_----------=xxxxx"
但是工作人员有:
Content-Type: multipart/alternative; boundary="_----------=xxxxx"
果然,看到multipart/mixed,现在可以正常工作了:
$email->content_type_set( 'multipart/alternative' );