About ActionMailer, Content-Type and Hell

Ruby on Rails is a very nice web development platform and generally using is very smooth. However, there are rough edges and today I discovered one of the least pleasant ones: Embedding images in HTML.

Generally, what you want to do is to create a multipart email with attached emails and then reference those emails in the HTML source code. You have to set the Content-Id header of the Image MIME part - say to - and then you can reference this image with <img src="cid:image1" />.

However, there is a problem when you try to do this naively with ActionMailer. The origin of the problem is TMail, the library ActionMailer uses to do the hard work of parsing and generating emails.

TMail uses its MessageIdHeader class to represent Content-Id headers. This class does some validation and is also used for the Message-Id header. Can you smell the problem already? Message ids must look like somestring@host but you would not assume that you have to format your content ids this way. If you format your Content-Id headers any other way then TMail will simply kick them out (I guess it throws some syntax errors but Rails is swallowing them silently).

To put it in a nutshell: If you need the Content-Id header then format it to look like a Message-Id header.

3 Responses to “About ActionMailer, Content-Type and Hell”

  1. Rita Hunkele Says:

    Fed up with getting low amounts of useless traffic for your site? Well i wish to share with you a new underground tactic that produces me personally $900 each day on 100% AUTOPILOT. I possibly could be here all day and going into detail but why dont you simply check their site out? There is a excellent video that explains everything. So if your seriously interested in producing simple money this is the website for you. Auto Traffic Avalanche

  2. Efrain Sinor Says:

    Who wants to hear something refreshing? I found something that is just like that Easy Button that they advertise on TV for Staples. It’s a little known secret that is only shared by some top level Internet gurus. The fact is, that this software is 100% legal, “white hat” and ethical, that even giant enterprises use it. The software needs very little babysitting so it’s basically set it up and forget it. This super affiliate push button software is the real thing, so if you’re planning to use it unethically, or use it for scam purposes, this software isn’t for you! It really is as simple as downloading the software and then pushing a button. This never seen before push button software proved that the best and most profitable traffic on the internet is free traffic. You might be tempted to try to disect this software in order to ’see the magic’ but why bother? All you really need to know is that you can download it (if the link hasn’t been taken down yet) and then push a button and watch the magic. Test it out -> http://cash411.info/go/218

  3. Nachaninnetty Says:

    Aiinheerdgg kohls coupons IOnbwrdeAopotree

Leave a Reply