Sending email to Heroku using external SMTP

I want to send emails from my rails app to Heroku. Since Heroku does not support SMTP, I am using an external SMTP server.

config / environment / production.rb has the following lines.

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => 'mydomain.com',
  :port => 587,
  :user_name => "myusername",
  :password => "password",
  :authentication => :plain,
  :enable_starttls_auto => true,
  :openssl_verify_mode => 'none' 
}

      

When I send email with "consolekun" it works fine. But it doesn't send email from the website. Oddly enough, "heroku logs -tail" shows "Mail sent ...". The letter is not actually delivered.

Does anyone know about this issue?

Thank.

Sam Kong

+2


source to share


3 answers


Have you tried this in config / enviornment.rb



ActionMailer::Base.smtp_settings = {
:address => 'mydomain.com',
:port => 587,
:user_name => "myusername",
:password => "password",
:authentication => :plain,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none' 
}

      

+3


source


Your configuration is correct. But you must put it in the correct environment file. In the case of Heroku deployments, this should be "production". The console works because it uses "development" as its environment. So put the following code in config / environment / production.rb

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
  :address => 'mydomain.com',
  :port => 587,
  :user_name => "myusername",
  :password => "password",
  :authentication => :plain,
  :enable_starttls_auto => true,
  :openssl_verify_mode => 'none' 
}

      



Hope it solves your problem.

+3


source


If it shows up as forwarded mail, I would guess that a configuration issue on your mail server is possibly preventing relaying from the Heroku IP range - this is most bizarre if it works through the heroku console rather than your app.

Do you think you are trying to use the SendGrid Heroku app just to troubleshoot any issues with your own mail server?

+1


source







All Articles