Multiple attachments to an HTML email, different mail clients

六月ゝ 毕业季﹏ 提交于 2019-12-08 13:02:15

问题


I'm trying to send an email with multiple attachments (for example, a jpg and a pdf) in a way that the attachments will show up correctly for Outlook, Gmail, and Mail on iOS.

What I've tried

  • If I send the email as a plain text email, all clients show the attachments.

  • If I include plain text and html parts to the email, both attachments disappear in iOS, while only the jpg disappears in Outlook. Gmail shows both attachments.

  • If I use plain and html parts, but in the body of the HTML include <img src="cid:<the content id of the file to attach>"> for the image file only, then Outlook and Gmail both show the pdf as an attachment and have the image embedded in the body. iOS has the image embedded and doesn't show that there is a pdf attachment at all.

  • If I abuse the <img>, just to see what happens, and include a <img src="cid:<the content id of the file to attach>"> for both the jpg and another for the pdf (I know, I know), then iOS finally (and bewilderingly) shows the image embedded and an icon to download the pdf (which works; if I tap it, the pdf renders as expected). But now Outlook shows the embedded image and a broken link image below it in the body (clicking on it does nothing), and no pdf attachment in the attachments area. Gmail shows the image embedded, and while it still shows the pdf as an attachment, the thumbnail is now blank and clicking on it won't render the pdf (though if you download it, then re-open the file in Chrome, it renders perfectly).

Question What is the lowest common denominator of headers, encoding, or whatever else is in the behind-the-scenes of composing the email bits that all three mail clients will understand. I'm not particular about the image being embedded vs being a just a regular attachment like the pdf, but regular attachment is preferred. I just need everyone I may send the email to, regardless of client, to see and be able to access the attachments.

I tried sending from an Outlook address to itself and to Gmail with the same attachments. Here's the difference in the structures of the emails:

The one that fails:

multipart/mixed
  multipart/alternative
    text/plain
    multipart/related
      text/html
      image/jpeg
      application/pdf

While the one that works is:

multipart/mixed
  multipart/alternative
    text/plain
    text/html
  image/jpeg
  application/pdf

Note: I'm using coldfusion (hence the src="cid:...." in the <img>, but that's irrelevant. I just need to know what the clients are expecting, and I can then hammer out how to bend a given language to produce that.

来源:https://stackoverflow.com/questions/57047950/multiple-attachments-to-an-html-email-different-mail-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!