Câu trả lời cho Mail multipart/alternative vs multipart/mixed gợi ý rằng file đính kèm nên đồng nghiệp của sứ điệp multipart/alternative
, như:Loại MIME để đáp ứng HTML, email, hình ảnh và văn bản thuần túy?
- multipart/mixed
- multipart/alternative
- text/plain
- text/html
- s ome/điều (bố: attachment)
- số/điều (bố: attachment)
- ...
- multipart/alternative
tôi muốn gửi email với một phần html với một số hình ảnh nội tuyến và một thay thế văn bản thuần túy. Bố cục MIME ưu tiên cho các phần khác nhau là gì? Một vài tùy chọn xuất hiện trong mã ví dụ và trong các câu hỏi khác, nhưng đã làm việc tốt nhất trong thực tế? độ nghiêng của tôi là thế này:
- multipart/alternative
- text/plain
- multipart/liên quan
- text/html (tham khảo hình ảnh bằng cách cid)
- image/gif
- hình ảnh/gif
- ...
Bằng cách đó, những hình ảnh rõ ràng với mục đích render phần html. Ví dụ đầy đủ về điều này sẽ là:
From: Rich Example <[email protected]>
To: A Recipient <[email protected]>
Subject: An example of email with images and a plain alternative
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="outer-boundary"
This is a MIME-encoded message. If you are seeing this, your mail
reader is old.
--outer-boundary
Content-Type: text/plain; charset=us-ascii
This message might make you :) or it might make you :(
--outer-boundary
MIME-Version: 1.0
Content-Type: multipart/related;
type="text/html"; start="<[email protected]>"; boundary="inner-boundary"
--inner-boundary
Content-Type: text/html; charset=us-ascii
Content-Disposition: inline
Content-ID: <[email protected]>
<html>
<body>
This message might make you
<img src="cid:[email protected]" alt="smile">
or it might make you
<img src="cid:[email protected]" alt="frown">
</body>
</html>
--inner-boundary
Content-Type: image/gif
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-ID: <[email protected]>
R0lGODlhEAAQAKEBAAAAAP//AP//AP//ACH5BAEKAAIALAAAAAAQABAAAAIzlA2px6IBw2
IpWglOvTahDgGdI0ZlGW5meKlci6JrasrqkypxJr8S0oNpgqkGLtcY6hoFADs=
--inner-boundary
Content-Type: image/gif
Content-Disposition: inline
Content-Transfer-Encoding: base64
Content-ID: <[email protected]>
R0lGODlhEAAQAKEBAAAAAAD//wD//wD//yH5BAEKAAIALAAAAAAQABAAAAIzlA2px6IBw2
IpWglOvTahDgGdI0ZlGW5meKlci75drDzm5uLZyZ1I3Mv8ZB5Krtgg1RoFADs=
--inner-boundary--
--outer-boundary--
Xuất hiện là bản in chính xác của câu hỏi mà nó refs: http://stackoverflow.com/questions/3902455/smtp-multipart-alternative-vs-multipart-mixed –
Một sự khác biệt nhỏ về ý định (cho dù tôi có truyền đạt rõ ràng nó không hay không) có thể phải làm với mục đích của các chấp trước. Nếu chúng là _for_ kết xuất phong phú (ví dụ: biểu trưng, cánh, v.v ...), chúng có phải là "trong" sự thay thế phong phú? Câu hỏi ref'd cũng không đề cập đến 'liên quan'. –