Created
April 7, 2011 16:41
-
-
Save stack/908166 to your computer and use it in GitHub Desktop.
Multipart Alternative + Multipart Related Email with ActionMailer for Rails 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Blog Post: http://www.shortround.net/2011/04/07/multipart-alternative-multipart-related-email-with-actionmailer-for-rails-3/