Email attachments
I want to be able to attach a file that I generate (on the fly, I dont want to save the file on my server) and send it out via email.
I have the text all done开发者_C百科, but I'm lost on how to attach the file to the email using sendmail
Thank you
See http://railscasts.com/episodes/206-action-mailer-in-rails-3
def registration_confirmation(user)
@user = user
attachments["rails.png"] = File.read("#{Rails.root}/public/images/rails.png")
mail(:to => "#{user.name} <#{user.email}>", :subject => "Registered")
end
You should be using Action Mailer that's built into Rails which supports sending emails with attachments.
For Rails 3.x - http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments
For Rails 2.3.8+ - http://guides.rubyonrails.org/v2.3.8/action_mailer_basics.html#sending-multipart-emails-with-attachments
For alternative consideration, I personally have had a good experience using Pony for email. It happens to have a lot of gem dependencies, but it is very nice to work with. See the README for more information.
精彩评论