griddler-mandrill icon indicating copy to clipboard operation
griddler-mandrill copied to clipboard

Inline attachments are not included in attachments field

Open joeyAghion opened this issue 10 years ago • 15 comments

Inline attachments are provided by the Mandrill webhook's images field and are not included in the attachments field. As such, they're not available in the Griddler::Email's attachments property.

I think they should be folded into the attachments property. Thoughts?

joeyAghion avatar Jan 16 '15 21:01 joeyAghion

I tentatively agree with that. I haven't used inline attachments with Mandrill. Do they keep a reference to the attachment in the email body? Would folding them into attachments remove that reference?

wingrunr21 avatar Jan 16 '15 21:01 wingrunr21

Yes, the email body can include something like <img src="cid:foobar">. The images field might then look like:

{"foobar"=>
  {"name"=>"foobar",
   "type"=>"image/jpeg",
   "content"=>
    "/9j/4AAQSkZJRgA...eiojyQf/9k="}}

Because the content-ID also appears as the name property, I think clients would still have all the necessary information if these were folded into attachments.

joeyAghion avatar Jan 19 '15 16:01 joeyAghion

Sounds good to me.

wingrunr21 avatar Jan 19 '15 16:01 wingrunr21

@joeyAghion are you planning on submitting a PR for this?

wingrunr21 avatar Jan 30 '15 18:01 wingrunr21

Hey @wingrunr21 I was but am still experimenting. It turned out that this wasn't quite enough to support our use case. All the data would be available in the revised attachments field, but it wouldn't be clear which attachments were inline or weren't. If someone else is interested in the half-fix I laid out here, I'm happy to PR it.

Another note, in case someone else pursue this: it turns out the Mandrill docs are misleading. The images field is supposed to include a base64 boolean just like attachments, but in practice it doesn't. Meanwhile, the contents are base64-encoded.

joeyAghion avatar Jan 30 '15 18:01 joeyAghion

This is biting me too. Going to see if I have better luck with Sendgrid.

rdetert avatar May 13 '15 08:05 rdetert

So this explains why some emails are missing attachments. iPhone users generally paste images into the emails instead of doing a classic attachment, and when they do that, my email processor is failing because it doesn't think that there's anything attached. Anybody actually get this working, or are we all just switching to sendgrid?

mfkp avatar Aug 09 '15 21:08 mfkp

I'd love a PR if someone sends one along. If the iPhone use case can consistently reproduce this then I can also try and find some time to work on a fix.

wingrunr21 avatar Aug 09 '15 21:08 wingrunr21

Hmm, I actually just had a friend test with Mail.app on iPhone and it actually worked fine in the attachments and pasting the image, but it seems like it's more of a problem when pasting an image inside the Gmail app. Might just be a Gmail issue in fact, so ignore what I said.

mfkp avatar Aug 09 '15 22:08 mfkp

haha ok. Well then, still looking for a PR or repeatable use case.

wingrunr21 avatar Aug 10 '15 13:08 wingrunr21

FYI - https://github.com/kat3kasper/griddler-mandrill

Just came back to this and found a way to reproduce. I use Airmail for my desktop email app. Attaching files normally comes through as attachments, but if you drag an image from finder into the email, it gets added as an inline attachment, which then shows up in the images hash instead of attachments.

The fork above seems to make it work, but it might not be suitable for all cases.

mfkp avatar Aug 25 '15 10:08 mfkp

Ok, great. I'll try and take a look at this then.

wingrunr21 avatar Aug 25 '15 14:08 wingrunr21

+1 Need it too!

holden avatar Dec 16 '15 13:12 holden

#27 has been merged. Images will be extracted and added into the attachments field of Griddler.

I've got a couple more enhancements coming (specifically around determining whether an attachment was inline or not).

wingrunr21 avatar Jan 11 '16 14:01 wingrunr21

Hi! I just came across this issue. I am trying to send inline attachments with griddler/mandrill for a Rails app. Whenever it gets processed the attachments have incorrect names. I inspected the raw_text of the email and noticed this:

<img src="cid:1620c85e6d0d0b594a91" alt="Yzma_(2)_(2)_(1)_(3)_(2)_(1).jpg" class="" style="max-width: 100%;">

it seems like the ActionDispatch::Http::UploadedFile created by rails is using the cid from the img tag as the filename, instead of the alt, which is the actual file name. Is there a reason the actual name of the uploaded file is not being used for the cid? How is the cid being made?

Any info would help! thanks!

TanookiMario avatar Mar 09 '18 21:03 TanookiMario