This code works perfectly on development and the email never arrives in production, even though they have the same configuration.
Config:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'domain.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:authentication => :plain,
:user_name => 'my_server@gmail.com',
:password => 'secret',
:enable_starttls_auto => true
}
Sending the email:
logger.warn "before mail call"
logger.warn ActionMailer::Base.smtp_settings
logger.warn(mail(to: "my_email@gmail.com", subject: "Testing", body: "email body").deliver!)
Server logs:
[2013-08-29 16:41:11.000] [WARN] -- before mail call
[2013-08-29 16:41:11.000] [WARN] -- {:address=>"smtp.gmail.com", :port=>587, :authentication=>:plain, :user_name=>"my_server@gmail.com", :password=>"secret", :enable_starttls_auto=>true}
[2013-08-29 16:41:11.000] [WARN] -- Date: Thu, 29 Aug 2013 16:41:11 +0200
From: my_server@gmail.com
To: my_email@gmail.com
Message-ID: <521f5d87537af_7af3da480050052@castillo05.fzi.de.mail>
Subject: Testing
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
email body
In development on my localhost it works perfectly. The email arrives almost instantly. On production the email never arrives and I get no error. I have already tried so many combinations of settings (with/without :enable_starttls_auto, :domain, not setting delivery_method, perform_deliveries, etc) and nothing has worked so far. I have also tried sending to other emails with no success.
Any ideas? Many thanks in advance
Try adding a from address (that is a valid email address) to your mail settings. I've had emails blocked before for this very reason. Maybe something like admin @ the domain name your site is hosted on?
mail(to: "my_email@gmail.com", subject: "Testing", body: "email body", from: "me@mydomainname.com").deliver!
Judging from your logs, it looks like you are going it right in the code department. The problem could be in your SMTP settings.
In particular, this post http://email.about.com/od/accessinggmail/f/Gmail_SMTP_Settings.htm is saying that gmail's smtp port in use is 465, I see you are using 587.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.