Skip to content

Instantly share code, notes, and snippets.

@stack
Created April 7, 2011 16:41
Show Gist options
  • Save stack/908166 to your computer and use it in GitHub Desktop.
Save stack/908166 to your computer and use it in GitHub Desktop.
Multipart Alternative + Multipart Related Email with ActionMailer for Rails 3
class EmbeddedMailer < ActionMailer::Base
def embedded_mail(to, from, subject, html_message, text_message, files = {}, embeds = {})
mail(:to => to, :from => from, :subject => subject) do |format|
format.text { render :text => text_message }
format.html { render :text => html_message }
end
# Embeds
embeds.each do |key, embed|
attachments.inline[key] = {
:content => File.read(embed[:path]),
:content_id => "<#{key}>"
}
end
# Attachments
files.each do |key, embed|
attachments[key] = File.read(embed[:path])
end
end
end
@stack
Copy link
Author

stack commented Jun 2, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment