Problem using inline attachments in E-Mails in Rails application

For some reason using an image within an html e-Mail (inline attachment) did display correctly in my rails application. Instead the attachment was displayed as a "normal" attachment in the attachment section of the E-Mail client.
1 answer

Apparently in Rails you need to manually set the MIME-Type of attachments, otherwise their filesize, filetype and other Metadata are not properly recognized by the E-Mail client and images will not be displayed within the html e-mail.
In this case using the hash :mime_type and the corresponding value 'image/png' in the rails controller solved this problem:

attachments.inline["img.png"] = {:data => File.read('img.png'), :mime_type => 'image/png'}

Comments

This problem falls into the category of "small details that you just have to know". Usually it would require googling the problem for some time, but you provided a straight to the point answer with a good code example. Good solution

Boian Velitchkov - Sun, 12/02/2018 - 21:11 :::