Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, but I'm lost on how to attach the file to the email using sendmail

Thank you

like image 811
user385948 Avatar asked Jan 06 '11 00:01

user385948


People also ask

How do I find attachments in email?

The simplest way to display Outlook's search tools is to click in the Search Current Mailbox box at the top of the message list. Once you place your cursor in that box, the ribbon will display the Search Tools options. To find all messages with attachments, select the Has Attachments button.


2 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
like image 88
BvuRVKyUVlViVIc7 Avatar answered Oct 21 '22 05:10

BvuRVKyUVlViVIc7


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

like image 38
Peter Brown Avatar answered Oct 21 '22 07:10

Peter Brown