Rails应用程序在Heroku发送电子邮件错误 [英] Rails App on Heroku Sending Email Error

查看:177
本文介绍了Rails应用程序在Heroku发送电子邮件错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Google Apps上托管了自己的域名。
我的电子邮件发送在我的笔记本电脑上以开发模式工作。

在Heroku(雪松堆栈)生产中出现此错误:
Net :: SMTPAuthenticationError(535-5.7.8未接受用户名和密码,在app / controllers / applicants_controller.rb:16:在`create'中了解更多信息):

这是我的production.rb文件:

  config.action_mailer.default_url_options = {:host => 'mydomain.com'} 
#ActionMailer配置
#设置生产 - 交付,没有错误发生
config.action_mailer.delivery_method =:smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default:charset => utf-8

config.action_mailer.smtp_settings = {
地址:smtp.gmail.com,
端口:587,
域名:mydomain .com,
认证:plain,
enable_starttls_auto:true,
user_name:info@mydomain.com,
密码:mypassword
}

以下是contacts_controller中的创建操作:

  def create 
@contact = Contact.new(params [:contact])

respond_to do | format |
if @ contact.save
ContactMailer.new_contact_notice(@contact).deliver
format.html {redirect_to(:root,:notice =>'谢谢,您的信息已成功发送。' )}

else
format.html {render:action => show}

end
end
end



<

  2013-05-07T05:01:54.773576 + 00: 00 app [web.1]:在2013-05-07 05:01:54 +0000 
2013-05-07T05:01:55.132454 + 00:00应用程序中启动POST/ applicants为108.208.197.181 [ web.1]:app / controllers / applicants_controller.rb:18:在`block in create'
2013-05-07T05:01:55.130426 + 00:00 app [web.1]:
2013 -05-07T05:01:55.132454 + 00:00 app [web.1]:
2013-05-07T05:01:55.130426 + 00:00 app [web.1]:发送邮件至姓名@ gmail。 com(185ms)
2013-05-07T05:01:55.132454 + 00:00 app [web.1]:
2013-05-07T05:01:55.132454 + 00:00 app [web.1 ]:Net :: SMTPAuthenticationError(535-5.7.8用户名和密码不被接受,详情请参阅
2013-05-07T05:01:55.132454 + 00:00 app [web.1]:app / controllers / applicants_controller .rb:16:在`create'
2013-05-07T05:01:55.132454 + 00:00 app [web.1]:):
2013-05-07T05:01:55。 132454 + 00:00 app [web.1]:

我尝试了一些我已经读过关于这个错误的信息,比如先登录到gmail账户。如果您尝试登录,我不会在任何设置中看到任何设置,所以我可以确认。



还有其他想法吗?

$ b $我花了三天时间,但我找到了答案。除了config / initializers中的setup_mail.rb,我已经检查并重新检查了邮件设置。就是这样。即使我在我的production.rb,application.yml和邮件程序文件中都有正确的邮件设置。我只有用户名name而不是完整的电子邮件地址name@domain.com。


I have my own domain name hosted on Google Apps. My email sending works in development mode on my laptop.

In production on Heroku (cedar stack) I get this error: Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted. Learn more at app/controllers/applicants_controller.rb:16:in `create'):

Here is my production.rb file:

config.action_mailer.default_url_options = { :host => 'mydomain.com' }
   # ActionMailer Config
   # Setup for production - deliveries, no errors raised
   config.action_mailer.delivery_method = :smtp
   config.action_mailer.perform_deliveries = true
   config.action_mailer.raise_delivery_errors = true
   config.action_mailer.default :charset => "utf-8"

   config.action_mailer.smtp_settings = {
     address: "smtp.gmail.com",
     port: 587,
     domain: "mydomain.com",
     authentication: "plain",
     enable_starttls_auto: true,
     user_name: "info@mydomain.com",
     password: "mypassword"
   }

Here is the create action in the contacts_controller:

 def create  
      @contact = Contact.new(params[:contact])  

      respond_to do |format|  
        if @contact.save  
          ContactMailer.new_contact_notice(@contact).deliver 
          format.html { redirect_to(:root, :notice => 'Thanks, Your information was successfully sent.') }  

        else  
          format.html { render :action => "show" }  

        end  
      end  
    end

Here is the full section of Heroku's logs indicating the error:

2013-05-07T05:01:54.773576+00:00 app[web.1]: Started POST "/applicants" for 108.208.197.181 at 2013-05-07 05:01:54 +0000
2013-05-07T05:01:55.132454+00:00 app[web.1]:   app/controllers/applicants_controller.rb:18:in `block in create'
2013-05-07T05:01:55.130426+00:00 app[web.1]: 
2013-05-07T05:01:55.132454+00:00 app[web.1]: 
2013-05-07T05:01:55.130426+00:00 app[web.1]: Sent mail to name@gmail.com (185ms)
2013-05-07T05:01:55.132454+00:00 app[web.1]: 
2013-05-07T05:01:55.132454+00:00 app[web.1]: Net::SMTPAuthenticationError (535-5.7.8 Username and Password not accepted. Learn more at
2013-05-07T05:01:55.132454+00:00 app[web.1]:   app/controllers/applicants_controller.rb:16:in `create'
2013-05-07T05:01:55.132454+00:00 app[web.1]: ):
2013-05-07T05:01:55.132454+00:00 app[web.1]: 

I've tried some of the things I have read about this error, such as loggin into the gmail account first. I don't see anywhere in settings where it asks you if you are trying to login so I can confirm that.

Any other ideas?

解决方案

It took my three days but I found the answer. I had checked and rechecked the mail settings everywhere except in the setup_mail.rb in config/initializers. That was it. Even though I had all the mail settings correct in my production.rb, application.yml and mailer files. I only had the username "name" instead of the full email address "name@domain.com".

这篇关于Rails应用程序在Heroku发送电子邮件错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆