下面是我目前如何使用 CURL 发送多部分/替代的示例。我在文本编辑器中编写这封电子邮件,将其保存到文件中并使用 CURL 发送整个内容。
To: "John Connor" <[email protected]>
From: "Sarah Connor" <[email protected]>
Subject: A multipart/alternative text/plain + text/html email
MIME-Version: 1.0 (Created with SublimeText 3)
Content-Type: multipart/alternative; boundary="content-boundary-alternative"
Preamble: This is a multipart/alternative message in MIME format.
--content-boundary-alternative
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
Good morning.
This is a message in text/plain format.
--content-boundary-alternative
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang=3D"en">
<head>
<meta charset=3D"utf-8">
<meta http-equiv=3D"Content-Type" content=3D"text/html">
</head>
<body>
Good morning.<br/>
<br/>
This is a message in text/html format.<br/>
</body>
</html>
--content-boundary-alternative--
然后我这样发送:
curl --verbose -ssl smtps://secure.example.com:465 --login-options AUTH=PLAIN --user [email protected]:Letmein#123 --mail-from [email protected] --mail-rcpt [email protected] --mail-rcpt-allowfails --upload-file complete-message.eml
到目前为止,一切都很好。
在阅读 CURL 手册页时,更具体地说,https://curl.se/docs/manpage.html#-F我注意到似乎有一种方法可以正确编码引用的可打印文本/html 内容以进行传输,-F, --form
encoder=quoted-printable
以便我使用不必手动进行。
任何人都可以提供我的方法的改编,包括encoder=quoted-printable
?
我有一种感觉,这需要将标题和正文放在单独的文件中,但我仍在阅读。
要使用选项发送多部分消息
-F
,您必须使用分组 (?) 符号:"=(;type=multipart/alternative"
/"=)"
[1]。(这是一个单行,但我在这里写这种方式澄清)
在此示例中,第一部分 (
=(
) 打开了一个组,其中的所有内容都被视为不同格式的相同内容 (type=multipart/alternative
)。然后=<
添加两部分 ( ),纯文本部分和 HTML 部分,均使用带引号的可打印算法进行编码。该组使用 关闭=)
。下一部分不在替代组内,它是附加的 (
=@
)。创建头文件时,请考虑:
参考:
[1] https://curl.se/docs/manpage.html#-F
[2] https://www.rfc-editor.org/rfc/rfc821