1

The server states that the email was sent to the correct address but I am not getting the message in my inbox.

My Setup_mail.rb file

ActionMailer::Base.smtp_settings ={
  :address          => "smtp.gmail.com",
  :port         => 587,
  :domain           => "gmail.com",
  :user_name        => "my_user_name@gmail.com",
  :password         => "my_password",
  :authentication       => "Plain",
  :enable_starttls_auto => true
}

My development.rb file is:

# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true #default value
config.action_mailer.delivery_method = :smtp #default value

My test.rb file is:

config.action_mailer.delivery_method = :smtp

I have tried multiple variations and am lost. I am running on a Windows 7 machine. I am running Ruby 1.8.7 and Rails 3.0.7

Can anyone help?

Here is my create method:

def create
 @user = User.new(params[:user])
 if @user.save
   UserMailer.registration_confirmation(@user).deliver
   sign_in @user
   redirect_to @user, :flash => { :success => "Welcome to the Sample App!" }
 else
   @title = "Sign up"
   render 'new'
 end
end

My user_mailer.rb class UserMailer < ActionMailer::Base

default :from => "my_user_name@gmail.com"

def registration_confirmation(user)
mail(:to => user.email, :subject => "Thanks for registering")

end
end
Skilatte
  • 25
  • 1
  • 6

5 Answers5

5

Take a look at your server. I'm pretty sure that you can see in your logs that it's actually trying to send the mail.

The problem is that Google doesn't trust your local IP address and your mails won't get delivered (not even to the spam directory). There is no way to work around this but using a whitelisted server.

If you try your app in production this should normally work, for example deploy your app to heroku to test it.

Andre Schweighofer
  • 2,759
  • 1
  • 26
  • 25
2

Try putting in .deliver at the end. That fixed this issue for me:

mail(:to .....).deliver!
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
mrvladimir
  • 519
  • 4
  • 8
0

I had this same issue, I was able to see that in my console mail was sent but in inbox nothing was appearing, one thing is that you can deploy your app on whitelisted server like heroku, or if you want to see just for testing purpose through your local just enable less secure apps in your browser and you should be able to see that email in your inbox https://myaccount.google.com/lesssecureapps

0

Try changing the authentication from a string to a symbol.

ActionMailer::Base.smtp_settings ={
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "gmail.com",
  :user_name            => "my_user_name@gmail.com",
  :password             => "my_password",
  :authentication       => :plain,
  :enable_starttls_auto => true
}
Caley Woods
  • 4,707
  • 4
  • 29
  • 38
  • I changed the authentication and email did not hit inbox. Thanks for your suggestion. – Skilatte Jun 14 '11 at 17:10
  • @user797995 it's interesting. The rails guide says that it needs to be a symbol `:plain` but in their example they use"plain" a string. – Caley Woods Jun 14 '11 at 17:32
  • I deployed to Heroku and this solved the issue. however this will still not work in development or test. – Skilatte Jun 14 '11 at 17:50
0

You should check that my_user_name@gmail.com has actually sent the email. We have had issues with this in the past when sending verification emails out through Gmail's SMTP server, since sending in bulk end up not sending at all.

I suggest you log into my_user_name@gmail.com and verify that there are no problems and that the emails are sent.

If not, you may want try a service like Send Grid to send outgoing emails.

Christian Fazzini
  • 19,613
  • 21
  • 110
  • 215