postmark-dotnet icon indicating copy to clipboard operation
postmark-dotnet copied to clipboard

Add support for inline attachments

Open gabephudson opened this issue 1 year ago • 2 comments

When using a content ID (CID) on an attachment (especially for images) it is important the attachment's content-disposition_value be set to "inline" and not "attachment". When set to attachment (as it is now), many email clients will display an attachment indicator or even the image as an attachment.

Please add a way to specify an attachment's content-disposition as "inline" instead of "attachment". There doesn't seem to be a way to change this in the API.

Here is an example of what is being sent and what needs to be sent for embedded attachments...

Content-Type: image/png; name=logosml.png Content-Transfer-Encoding: base64 Content-Id: Content-Disposition: attachment; filename=logosml.png

What needs to be sent for embedded images is…

Content-Type: image/png; name=logosml.png Content-Transfer-Encoding: base64 Content-Id: Content-Disposition: inline; filename=logosml.png

(Content-Disposition: inline is what value is needed)

gabephudson avatar May 01 '23 17:05 gabephudson

Content-Disposition is set to inline when you set contentId in PostmarkMessageAttachment. To correctly inline an image the contentId must match the src attribute of an img tag.

await client.SendMessageAsync(
  new PostmarkMessage(@from, to, subject, text, "<p>Testing inline image</p><img src=\"cid:my-image\" />")
  {
      Attachments = new List<PostmarkMessageAttachment>
      {
          new PostmarkMessageAttachment(imageBytes, "image.jpg", "image/jpg", "cid:my-image")
      }
  });

Let me know if I can help with anything else!

MariuszTrybus avatar May 08 '23 08:05 MariuszTrybus

Sorry, it looks like the content-id value got killed by GitHub because it had angle brackets in it. :|

Thanks for your response. I discovered what the issue was/is. It was unclear I had to include "cid:" as part of the contentid string in the "AddAttachment" method. I was mistakenly doing the following...

new PostmarkMessageAttachment(imageBytes, "image.jpg", "image/jpg", "my-image")

Once I added the "cid:" to the string, it is working as expected. :) I don't know if there would be a reason to ever include a contentid without a "cid:"? If not, may want to add a check for that in the code and add the "cid:" if missing?

Thanks again for your help!

gabephudson avatar May 08 '23 14:05 gabephudson