views:

3103

answers:

6

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.

+2  A: 

yes check out the ruby docs...http://ruby-doc.org/stdlib/

the package you want to look at is net/smtp

there is also

http://www.rfc20.org/rubymail/(ruby mail) which is popular and make it a little easier

Mark Lubin
Thanks. Seems to be what I'm looking for.
sker
+8  A: 

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

Orion Edwards
Yeah but this is my first project in rails and I'm getting tired of having to relearn everything to do it the rails way. I wanted something straightforward like net/smtp. Thanks for the link though, I'll check it out for my next project.
sker
Getting tired of learning to do it the rails way? Why are you using rails then? Isn't that the whole point of learning it?
Orion Edwards
Orion's comment ++
Ian Terrell
+3  A: 

There's also TMail.

Farrel
Rails uses TMail behind the scenes to do it's mailing, so technically you'll be using it anyway :-)
Orion Edwards
TMail requires something like net/smtp to actually send the mail. It is a convenient to create a more complicated message though, it breaks down the different constituents of advanced e-mail usage scenario's, like CCs, BCCs, multi-part MIME etc.
Felix Ogg
+3  A: 

Another excellent solution is a gem called pony. It is exactly like php's mail() function. Simply and easy.

vrish88
A: 

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
Joe W.
A: 

I'm concerned that if you don't want to use ActionMailer that maybe you just don't get rails. ActionMailer makes sending email with good templating and the like very very easy, you really should look into it.

railsninja