Correct email format for Email with Plain, HTML and an Attachment in SMTP?

后端 未结 2 1262
北恋
北恋 2021-01-06 02:19

The Problem:

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

相关标签:
2条回答
  • 2021-01-06 02:25

    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.

    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.

    0 讨论(0)
  • 2021-01-06 02:49

    It turns out the problem is incredibly subtle.

    Hotmail conventionally (this was the original email I based it on ), uses the term "multipart/alternative" for multiple parts of the email. I used 'multipart/alternative' in my email.

    It turns out yahoo does not like 'multipart/alternative' and will only correctly display the plain text, html and attachment correctly when instead the term 'multipart/mixed' is used (as I noticed yahoo compliant emails use this term instead of alternative), in combination with ejdyksen's suggestion (neither suggestion works by itself for yahoo's server though).

    Although, technically speaking, this is the 'correct' answer, I will leave ejdyksen's answer selected because his efforts had shown it was some server-side technicality (his SMTP server and hotmail's both displayed the attachment, yahoo's didn't). Politely upvote ejdyksen's answer instead as he did most of the legwork.

    0 讨论(0)
提交回复
热议问题