Gmail on heroku with Rails 3

不羁岁月 提交于 2019-12-19 05:20:42

问题


I am trying to send emails from Heroku up and running. At the moment I can send emails from Heroku via the "tutorial" at http://blog.heroku.com/archives/2009/11/9/tech_sending_email_with_gmail/, so that is fine.

My current problem is that when I got it to work at Heroku, I can't get it to work in development. I had that up and running with settings in either environment.rb or development.rb, but after the stuff in the tutorial kicked in and I removed the settings in env/dev.rb it doesn't work.

In the browser I get the error msg: 530-5.5.1 Authentication Required. Learn more at (it cuts after Learn more at)

In the server console I get the error msg: Net::SMTPAuthenticationError (530-5.5.1 Authentication Required. Learn more at
):

I have set heroku config:add GMAIL_SMTP_USER=username@gmail.com and heroku config:add GMAIL_SMTP_PASSWORD=yourpassword (with my info ;)), but it doesn't help.

Any ideas what I am doing wrong?

Can I do it the old way in development and skip the heroku script in some way?

Cheers Carl


回答1:


Just do as the above user has said about the SMTP settings.
In addition to that, Gmail blocks unidentified logins from a application to your account without you verifying it.
So go to your Gmail client and log in there.

If that doesn't work go to unlock captcha




回答2:


I have personally encountered that error sending with Gmail and needed to solve an unlock CAPTCHA to allow the sending. Gmail can be picky with security sometimes, and the documentation is not very apparent.

The full message should read:

530-5.5.1 Authentication Required. Learn more at https://support.google.com/mail/bin/answer.py?hl=en&answer=14257

so check out that link and follow the directions there.

You might need to sign into the Gmail webapp or (what I had to do), solve the unlock CAPTCHA. Or perhaps it is something in your app or environment, but following the Google directions is worth a shot.




回答3:


Please add the following code in config/environments/development.rb

config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true

and also make sure you have added the following in config/initializers/smtp_gmail.rb

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



回答4:


Did you export those environment variables on your local machine? You say you're adding the GMAIL_SMTP... to heroko config, but are you:

$ export GMAIL_SMTP_USER=username@gmail.com $ export GMAIL_SMTP_PASSWORD=yourpassword

I ran into your question because I also have email working in dev, and wondered if the 2009 post about how to get smtp & gmail to work on heroku is still necessary. Apparently so.




回答5:


I have mail being sent via Gmail on a heroku app. Here is my config if it helps. I am not using any third party plugins, just Rails 3.

In config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address  => "smtp.gmail.com",
  :port  => 587,
  :user_name  => "foo@bar.com",
  :password  => "foobar",
  :authentication  => :plain,
  :enable_starttls_auto => true
}

In config/environments/production.rb

After the end statement for the config block, I have added

ActionMailer::Base.smtp_settings[:enable_starttls_auto] = false



来源:https://stackoverflow.com/questions/7855870/gmail-on-heroku-with-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!