Created
August 19, 2009 18:44
-
-
Save iamwilhelm/170564 to your computer and use it in GitHub Desktop.
This file contains 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 SomeMailer < ActionMailer::Base | |
# assumes that there's a file named pretty_template.html.erb in app/views/some_mailer | |
def html_email_with_attachment(email_address, msg) | |
recipients [email_address] | |
from "hello@world.com" | |
subject "This is an html email with an attachment" | |
# have to set content_type explicitly | |
content_type "multipart/alternative" | |
# then set the html part. Note that there is no call to body(), but | |
# the second argument is a hash containing what you'd put into body() normally. | |
part(:content_type => "text/html", | |
:body => render_message("pretty_template", :message => msg) | |
attachment(:content_type => "text/csv", | |
:filename => "attachment.csv", | |
body => CSVGenerator.generate_csv_string) | |
# as a note, all attachment is doing is adding transfer_encoding and disposition | |
# part(:content_type => "text/csv", | |
# :transfer_encoding => "base64", | |
# :disposition => "attachment", | |
# :filename => "attachment.csv", | |
# :body => CSVGenerator.generate_csv_string) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment