Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to send mail with Ruby on Rails

What is the simplest way to send mail using Ruby on Rails? Is there a way to send mail directly via ruby and skip all the rails models and complexity, just like php's mail() function?

Thanks for your help.

like image 786
sker Avatar asked Oct 25 '08 22:10

sker


People also ask

What is action mailer?

Action Mailer allows you to send emails using mailer classes and views. Mailers work very similarly to controllers.


3 Answers

The simplest way in plain old ruby is to use net/smtp. However rails has it's own built in mailing facilities, because sending mail is something that is pretty common. The best way to do it in rails, is to use a Mailer model

like image 116
Orion Edwards Avatar answered Nov 08 '22 04:11

Orion Edwards


Make sure you replace all the example.com's with real values:

require 'net/smtp'
Net::SMTP.start('smtp.example.com', 25) do |smtp|
  smtp.send_message "Subject: testing from ruby", '[email protected]', ['[email protected]', '[email protected]']
end
like image 41
Joe W. Avatar answered Nov 08 '22 05:11

Joe W.


There's also TMail.

like image 4
Farrel Avatar answered Nov 08 '22 05:11

Farrel