Rails Attachments Inline Are Not Shown Correctly in Gmail

Rails attachments inline are not shown correctly in gmail

After all i found a solution: all you need to do is set the mime-type and encoding of the attachment.

attachments.inline['blank'] = {
:data => File.read("#{Rails.root.to_s + '/app/assets/images/blank_500x500.png'}"),
:mime_type => "image/png",
:encoding => "base64"
}
attachments.inline['discount-deal-triangle'] = {
:data => File.read("#{Rails.root.to_s + '/app/assets/images/discount-deal-triangle.png'}"),
:mime_type => "image/png",
:encoding => "base64"
}

That did the trick for me.

Rails inline mail attachments not working properly

Well, the solution or rather workaround that worked was to upgrade to Rails 4. I am able to send inline images without any problem in Rails 4.

Rails mailer error with inline attachment

I looked at the mail source.

This error can only occur if the content id field is nil. However calling .url should be setting the content id to an empty string unless has_content_id? is returning true, meaning there's already a content id field in the multipart header.

This is not happening, so we must have a strange case where the header object is reporting has_content_id? true yet is returning a content_id of nil.

Try setting the content id field explicitly just after you set the graphic.

attachments['visionamos.png'].header['content-id'] = 'logo.graphic'

If this works, there's still the puzzle of why it's necessary. Did you make any other changes to mailer configuration or code? Did you upgrade any gems?

Addition responding to question edit

The header parser seems to be failing because there are spaces in the id ...@MacBook Pro de Ruben.mail. Try re-naming the computer with no spaces! I guess this constitutes a bug in mail. Spaces should be elided or replaced with a legal character.

My guess is that this will also fix the original problem, and you won't need to set the content-id manually any more. Hence another guess: you changed machine name or moved development to a new machine. and that's when the bug appeared!

Why is ActionMailer randomly not displaying the plain text part of my multipart/alternative emails?

I had this issue a while back with DJ and ActionMailer- turned out I was running DJ on two utility servers where I thought it was only one, and my deploy hook only restarted the DJ daemon on one and not the other and that caused a whole bunch of problems like this.

The thing that had my head splitting the most was the 60% thing- where some were going out fine where others were completely deformed, but the DJ daemon being reset on one server and not the other totally explained the inconsistency.

Hope this helps!



Related Topics



Leave a reply



Submit