Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send email from rails console

I'm trying to send out some mails from the console on my production server, and they're not going out. I can't work out why. I have just your standard email setup with sendmail. When i call the Mailer.deliver_ method i get this back:

#<TMail::Mail port=#<TMail::StringPort:id=0x3fe1c205dbcc> bodyport=#<TMail::StringPort:id=0x3fe1c2059e00>> 

EDIT: Added some more info:

So, for example, i have this line in my controller when a new user signs up, to send them a "welcome" email:

 Mailer.deliver_signup(@user, request.host_with_port, params[:user][:password]) 

This works fine. I thought that i should be able to do the same thing from the console, eg

user = User.find(1) Mailer.deliver_signup(user, "mydomainname.com", "password") 

When i do this, i get the Tmail::StringPort object back, but the mail appears to not get sent out (i'm trying to send emails to myself to test this).

I'm on an ubuntu server in case that helps. thanks - max

like image 705
Max Williams Avatar asked Jul 16 '10 16:07

Max Williams


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.


2 Answers

Quicker version:

ActionMailer::Base.mail(   from: "[email protected]",    to: "[email protected]",    subject: "Test",    body: "Test" ).deliver_now 
like image 105
jmgarnier Avatar answered Sep 22 '22 07:09

jmgarnier


I ran into a similar problem this morning on a Rails 3 app where I called:

UserMailer.activation_instructions(@user) 

This gave me the data but did not send the e-mail out. To send, I called:

UserMailer.activation_instructions(@user).deliver 

This did the trick. Hopefully this might work for you too!

like image 36
sscirrus Avatar answered Sep 23 '22 07:09

sscirrus