Wednesday, August 19, 2009

Sending HTML emails with attachments in Rails

Here's something you might have missed in Rails.

From ActionMailer's Documentation:

Implicit template rendering is not performed if any attachments or parts have been added to the email. This means that you‘ll have to manually add each part to the email and set the content type of the email to multipart/alternative.

If you want to have pretty html templates and have an attached file, you can't just set the content_type to "text/html" and call attachment. You need to do it separately, like so:

There, now you can have html and your attachments too. Reference: