Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamwilhelm/170564 to your computer and use it in GitHub Desktop.
Save iamwilhelm/170564 to your computer and use it in GitHub Desktop.
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