1
votes

I've created a html formatted email containing a table and want attachments to appear in rows in the table. I can't manage to get the attachments to appear in the body of the email at all, instead they come through (in our Lotus Notes 8.5.3 client) as attachments all grouped in the header under the attachment twistie.

Is there any way for the attachments to display in the body of the email instead of the header?

(Updated Jan 20, 2014) For reference, I looked for sample methods for adding attachments. Mark Leusink here and Tony McGuckin here posted great snippets for building HTML/MIME emails, so I used these as a starting point, but couldn't find anything to get the attachment into the body. Stephan has clarified why that is in his response below.

2
Please post an example of the code you've tried so far... stackoverflow.com/help/how-to-askTim Tripcony
Sorry Tim, I should have given examples of what I had looked at so far. I've updated the post.PNelson

2 Answers

3
votes

Mime doesn't contain attachments in message bodies, so they won't show up. However with a little trickery you can get what you want:

  • add another attachment containing an icon to be shown for the attachment. One generic or one each
    • in your table construct a href followed by img src pointing to image and attachment
  • you can read more about the URL format here

http://en.m.wikipedia.org/wiki/MIME Bonus track: there is a notes item to stop attachments to be shown (can recall which one) If you smuggle that in as header...

2
votes

Stephan has already pointed you in the right direction, but I'll just add a bit more detail in case others stumble upon this question.

You need to create a multipart MIME structure -- specifically multipart/related -- containing an HTML part (Content-Type: text/html) and one or more attachment parts. Each attachment part should have a Content-ID header with a unique identifier.

Your HTML part will usually have at least one anchor element corresponding to each of the attachment parts. The href attribute can refer to the attachment by Content-ID. Here's an example:

<a href="cid:_attachment_one_">someFile.ext</a>

It's important the substring after "cid:" is an exact match of the Content-ID header of the corresponding attachment part. That's how the anchor and the attachment part are tied together.

As Stephan said, http://en.wikipedia.org/wiki/MIME is a good reference. However, the MHTML page (http://en.wikipedia.org/wiki/Mhtml) might be a better starting point. MHTML is a subset of MIME that focuses on multipart/related and HTML.