While ActionMailer claims to support multipart emails, that support is severely limited.
If you have a multipart/alternative email and are using layouts, multipart layouts don't work, the text/html layout will be used for the text/plain alternative part.
You also can't embed an image to use via <img src="cid:blah"> (or CSS, etc.) in the text/html section of your multipart/alternative mail. (I want the image to be controlled via the img element and styles, not plopped into the middle of my HTML section.)
While this ticket was closed due to lack of a test, the fix involves the modification of a constant which wouldn't be tested anyhow. (It seems nobody bothered to inform TMail about this problem either.)
Enough griping!
I managed to find a solution to these two problems!
To take care of the first problem I overrode initialize_template_class in my mailer class and manually set the template format for the part:
def initialize_template_class(assigns)
template_format = assigns.delete :template_format
template = super
template.template_format = template_format if template_format
template
end
Then wrote a render_multipart method that manually chooses the template and layout to render:
For Apple mail to properly display a multipart/alternative mail the top-level MIME type needs to be multipart/alternative. The text/html alternative part is wrapped inside a multipart/related part that also contains the embedded image. (When viewing the mail as text/plain the image attachment doesn't appear on the attachments bar. When viewing as text/html it does, but I don't think that there's a way to hide it from the attachments bar.)
Fixing this For Good™ seems to involve teaching ActionPack's views about how to read MIME extensions (reset.text.plain.erb and reset.text.html.erb) instead of filetype extensions (show.html.erb and show.xml.erb) like what is used by ActionController's views. The ticket seems to indicate somebody's trying to figure out how to do that.
To take care of the embedding of an image in an email for use in the HTML part I removed the restriction on Content-Id for a part header from the patch to TMail: