Email Attachments

I want to be able to attach the file that I generate (on the fly, I do not want to save the file on my server) and send it by email.

I have text, everything is done, but I lost how to attach a file to email using sendmail

thanks

+6
ruby ruby-on-rails
source share
3 answers

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 
+19
source share

You must use the Action Mailer 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

+5
source share

For an alternative consideration, I had good experience using Pony for email. This happens to have many dependencies on gems, but it’s very nice to work with them. See README for more information.

+1
source share

All Articles