SMTP 中带有纯文本、HTML 和附件的电子邮件的正确电子邮件格式? [英] Correct email format for Email with Plain, HTML and an Attachment in SMTP?

查看:272
本文介绍了SMTP 中带有纯文本、HTML 和附件的电子邮件的正确电子邮件格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我尝试复制 yahoo 和 hotmail 使用的基于 SMTP 的标头/电子邮件并通过 Telnet 发送它们,但我收到的电子邮件没有显示包含的附件​​,但它确实正确显示了消息.

I tried to copy the SMTP based headers/emails used by yahoo and hotmail and send them over Telnet, but the email I get does not display the included attachment, but it does display the message correctly.

我怀疑是什么原因造成的:

我认为我的电子邮件格式不正确,尽管在网上搜索了许多文章(以及试图掌握复杂且难以阅读的 RFC),但我没有找到任何有用或简洁的文章来解释如何使用所有SMTP 中的三个(纯文本、HTML 和附件)正确.我花了几天时间尝试更改代码,但我要么得到只是消息(无附件),要么得到整个 SMTP 数据正文显示(包括边界、html 代码等).

I believe I have the incorrect format for the email, and despite searching numerous articles online (as well as trying to grasp complicated and difficult to read RFCs), I have not found any helpful or concise articles that explain how to use all three (Plain, HTML and an attachment) in SMTP correctly. I've spent several days trying to alter the code, but I either get just the message (no attachment) or the entire SMTP Data body displaying (including boundaries, html code etc).

我希望通过这个问题实现的目标:

我希望有人可以查看我在下面收集的信息,并能够告诉我我遗漏了什么(或者电子邮件的格式究竟有多么不正确).

I'm hoping someone can look over the information I've gathered below, and be able to tell me what I am missing (or how exactly the formatting of the email is incorrect).

调试信息:

我将发送到 SMTP 服务器的信息的副本提供给文件,并将信息粘贴到 pastebin(删除/编辑了任何个人信息 - Base64 编码附件只是另一封电子邮件的文本文件从 IMAP 获取):

I fed a duplicate of the information I sent to the SMTP server to file, and I've pasted the information to pastebin (with any personal information removed/edited out - the Base64 encoded attachment is just a text file of another email gotten from IMAP):

信息逐字发送(减去控制字符)到 SMTP 服务器:

http://pastebin.com/QYwzWT0S

我在电子邮件客户端中看到的内容(注意没有附件):

http://i45.tinypic.com/29b1zci.jpg

我下载电子邮件时 IMAP 看到的内容(注意格式不正确):

http://pastebin.com/zv3PBr8N

正确格式的电子邮件在 IMAP 中应该是什么样子:

http://pastebin.com/3yBySbxU

我怀疑 SMTP 误解了我发送的内容,这就是 IMAP 尝试检索电子邮件时缺少 multipart/alternative 的原因.我到底做错了什么?服务器期望什么?

I suspect SMTP is misinterpreting what I am sending, which is why the multipart/alternative is missing when IMAP tries to retrive the email. What exactly am I doing wrong? What does the server expect?

[感谢您的支持 - 我可以重新启用链接!]

[Thank you for the upvotes - I can re-enable the links!]

推荐答案

我清理了多部分边界说明符并得到了这个,它适用于我的服务器(我在这里省略了 SMTP 命令):

I cleaned up the multipart boundary specifiers and got this, which works for me on my server (I've left off the SMTP commands here):

From: "Edited Out" <editedout@yahoo.com> 
To: "Edited Out" <editedout@yahoo.com> 
Subject: Testing 4
MIME-Version: 1.0
Content-Type: multipart/alternative;
  boundary="boundary-type-1234567892-alt"

--boundary-type-1234567892-alt
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


Testing the text to see if it works!

--boundary-type-1234567892-alt
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


<html>Does this actually work?</html>

--boundary-type-1234567892-alt
Content-Transfer-Encoding: base64
Content-Type: text/plain;name="Here2.txt"
Content-Disposition: attachment;filename="Here2.txt"

KiAxMyBGRVRDSCAoQk9EWVtURVhUXSB7NjU5fQ0KLS1fZjZiM2I1ZWUtMjA3YS00ZDdiLTg0NTgtNDY5YmVlNDkxOGRhXw0    KQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PSJpc28tODg1OS0xIg0KQ29udGVudC1UcmFuc2Zlci1FbmNvZG    luZzogcXVvdGVkLXByaW50YWJsZQ0KDQoNCkp1c3Qgc2VlaW5nIHdoYXQgdGhpcyBhY3R1
YWxseSBjb250YWlucyEgCQkgCSAgIAkJICA9DQoNCi0tX2Y2YjNiNWVlLTIwN2EtNGQ3Yi04NDU4LTQ2OWJlZTQ5MThkYV8    NCkNvbnRlbnQtVHlwZTogdGV4dC9odG1sOyBjaGFyc2V0PSJpc28tODg1OS0xIg0KQ29udGVudC1UcmFuc2Zlci1FbmNvZG    luZzogcXVvdGVkLXByaW50YWJsZQ0KDQo8aHRtbD4NCjxoZWFkPg0KPHN0eWxlPjwhLS0N
Ci5obW1lc3NhZ2UgUA0Kew0KbWFyZ2luOjBweD0zQg0KcGFkZGluZzowcHgNCn0NCmJvZHkuaG1tZXNzYWdlDQp7DQpmb25    0LXNpemU6IDEwcHQ9M0INCmZvbnQtZmFtaWx5OlRhaG9tYQ0KfQ0KLS0+PC9zdHlsZT48L2hlYWQ+DQo8Ym9keSBjbGFzcz    0zRCdobW1lc3NhZ2UnPjxkaXYgZGlyPTNEJ2x0cic+DQpKdXN0IHNlZWluZyB3aGF0IHRo
aXMgYWN0dWFsbHkgY29udGFpbnMhIAkJIAkgICAJCSAgPC9kaXY+PC9ib2R5Pg0KPC9odG1sPj0NCg0KLS1fZjZiM2I1ZWU    tMjA3YS00ZDdiLTg0NTgtNDY5YmVlNDkxOGRhXy0tDQopDQpmbHlubmNvbXB1dGVyIE9LIEZFVENIIGNvbXBsZXRlZA


--boundary-type-1234567890-alt--

多部分电子邮件中的边界说明符是不太可能出现在电子邮件正文/附件中的任意文本.当它在前面显示两个破折号时,表示新部分的开头(包括第一部分.当它在开头和结尾显示两个破折号时,表示邮件的结尾.

The boundary specifier in a multipart email is any arbitrary text that's not likely to appear in the email body/attachments. When it shows up with two dashes in front, that specifies the beginning of new part (including the very first part. When it shows up with two dashes at the beginning and end, that specifies the end of the mail.

您的原始邮件在邮件中间有这个结束边界"标记(就在 <html>这真的有效吗?</html>),并且有两个不同的边界标记(--boundary-type-1234567890--boundary-type-1234567892-alt).这就解释了为什么附件被遗漏了.

Your original mail had this "end boundary" marker in the middle of the mail (right after <html>Does this actually work?</html>), and had two different boundary markers (--boundary-type-1234567890 and --boundary-type-1234567892-alt). That explains why the attachment was left off.

这篇关于SMTP 中带有纯文本、HTML 和附件的电子邮件的正确电子邮件格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆