Rails sending emails via gmail not working in heroku server but ok in localhost
I’ve encountered a problem that my rails app can send email via gmail properly in my computer but not working in heroku server (get an error: “Must issue a STARTTLS command first”).
Following by this post:
-
download tls_smtp.rb. (found from this post)
-
put it into your app lib directory
-
import it in config/environment.rb
require 'tls_smtp'
Then upload to heroku, it’s done!
I didn’t add additional config in config/environments/production.rb as this post said. But it still work.
This is my mailer config (I put it in config/initializers/mail.rb): ActionMailer::Base.smtp_settings = { :enable_starttls_auto => true, :address => ‘smtp.gmail.com’, :port => 587, :domain => ‘gmail.com’, :authentication => :plain, :user_name => ‘xxxxxx@gmail.com’, :password => ‘******’ }
Hope this helps