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.


Use file extension in inline array. Example:

attachments.inline['blank.png'] = 
  File.read(Rails.root.join('app', 'assets', 'images', 'blank_500x500.png')

This way Rails will guess the file mime_type and encoding. At least Rails 4.2 will do so.

You may also refer to https://stackoverflow.com/a/25810153/2041318 where you can find nice helper method for mailer inline images.