Sending mail using Rails 3 in a development environment

I am sure they have asked this millions of times, but I can’t find anything that works for me, so I ask again!

I just need a way to send emails using ActionMailer in rails 3. I followed numerous tutorials, including the Railscasts tutorial on the new ActionMailer, and I can see the emails created, but I don’t receive them.

I tried a bunch of different ways, but they usually come down to setting the following options

ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => "587", :domain => "gmail.com", :user_name => "xxx@gmail.com", :password => "yyy", :authentication => "plain", :enable_starttls_auto => true } 

I tried the above code (with valid gmail data, of course) in my config / environment.rb, config / environment / development.rb and currently have it in my own initializer config / initialisers / setup_mail.rb

I also tried with several different SMTP servers, including Gmail and Sendgrid, respectively setting smtp options, but still nothing. I can see the mail in the terminal and the development log and what it is.

Does anyone know of any other error that I might have missed that I need to configure for ActionMailer? Otherwise, is there a way to get more information about why emails are not sent? I have

 config.action_mailer.raise_delivery_errors = true 

in my config / development.rb, but the development log still shows the same thing as in the terminal.

For what it's worth, I'm developing a Ubuntu 10.04 laptop in case you need some kind of specific setup for this.

Thank you very much

+53
ruby-on-rails ruby-on-rails-3 actionmailer
Nov 30 '10 at 11:23
source share
7 answers

Well, I solved the problem, but why it works, and other methods do not, I don’t know.

The solution was to create an initializer in config / initialisers / setup_mail.rb containing the following

 if Rails.env != 'test' email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/email.yml")) ActionMailer::Base.smtp_settings = email_settings[Rails.env] unless email_settings[Rails.env].nil? end 

Then I added config / email.yml, which contains information about the dev and production accounts.

 development: :address: smtp.gmail.com :port: 587 :authentication: plain :user_name: xxx :password: yyy :enable_starttls_auto: true production: :address: smtp.gmail.com :port: 587 :authentication: plain :user_name: xxx :password: yyy :enable_starttls_auto: true 

Like I said, I don’t know why, but it seems to be a trick. Thanks to everyone for the pointers.

+55
Dec 07 '10 at 14:39
source share

I have the following in config/environments/development.rb

 config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_deliveries = true 

The actual mail configuration, config.actionmailer.* I, is placed in config\application.rb .

Hope this helps :)

+27
Nov 30 '10 at 12:32
source share

Try using sendmail instead of smtp.

 ActionMailer::Base.delivery_method = :sendmail ActionMailer::Base.sendmail_settings = { :address => "smtp.gmail.com", :port => "587", :domain => "gmail.com", :user_name => "xxx@gmail.com", :password => "yyy", :authentication => "plain", :enable_starttls_auto => true } 
+5
Nov 30 '10 at 12:11
source share

Three things.

First, the port is an integer and does not need quotes, as in the first example. (But I think the string should work.)

Secondly, do not forget to restart your server every time you modify this (or any) initializer file. This may explain why you did not notice an error after adding:

config.action_mailer.raise_delivery_errors = true

Without this error message, it is difficult to determine why the mail was not, but now. One possibility is to use double quotes around the password. If you used a strong password and had a token in your password that was not escaped, it could be reinterpreted. (i.e., "P@ssw\0rd" will become P@ssrd ). It is for this reason that I always use single quotes in my code, unless I specifically need syntactic sugar.

Finally, enable_starttls_auto: true is standard and unnecessary.

+3
May 30 '11 at
source share

Just put the whole configuration in: config / environment / development.rb

I mean

 ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.smtp_settings = { :address => "smtp.gmail.com", :port => "587", :domain => "gmail.com", :user_name => "xxx@gmail.com", :password => "yyy", :authentication => "plain", :enable_starttls_auto => true } 

and

 config.action_mailer.raise_delivery_errors = true config.action_mailer.perform_deliveries = true 

It worked for me.

+1
Feb 05 '14 at 10:21
source share

ActionMailer::Base.delivery_method = :sendmail
and
config.action_mailer.perform_deliveries = true

were the two necessary steps that led me to this problem

+1
Aug 08 '15 at 15:55
source share

Also, your gmail username is not an alias.

Link: https://support.google.com/mail/answer/12096?hl=en

0
Sep 02 '13 at 5:44 on
source share



All Articles