ruby-on-rails-3 - Heroku 上的 Rails 应用程序发送电子邮件错误

标签 ruby-on-rails-3 heroku gmail

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

在 Heroku(雪松堆栈)上的生产中,我收到此错误: Net::SMTPAuthenticationError(535-5.7.8 用户名和密码不被接受。了解更多信息 app/controllers/applicants_controller.rb:16:in `create'):

这是我的 Production.rb 文件:

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: "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3f565159507f52465b50525e5651115c5052" rel="noreferrer noopener nofollow">[email protected]</a>",
     password: "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 => 'Thanks, Your information was successfully sent.') }  

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

        end  
      end  
    end

以下是 Heroku 日志中指示错误的完整部分:

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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ee808f838bae89838f8782c08d8183" rel="noreferrer noopener nofollow">[email protected]</a> (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]: 

我已经尝试了一些我读过的有关此错误的方法,例如首先登录 gmail 帐户。我在设置中没有看到任何地方询问您是否正在尝试登录,因此我可以确认这一点。

还有其他想法吗?

最佳答案

我花了三天时间但找到了答案。除了 config/initializers 中的 setup_mail.rb 之外,我已经检查并重新检查了所有地方的邮件设置。就是这样。即使我的 production.rb、application.yml 和邮件程序文件中的所有邮件设置都是正确的。我只有用户名“name”,而不是完整的电子邮件地址“[email protected]”。

关于ruby-on-rails-3 - Heroku 上的 Rails 应用程序发送电子邮件错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16422316/

相关文章:

ios - 发生多个POST请求

node.js - Heroku 默认的 Node.js 应用程序

java - 如何在Android应用程序中实现通过gmail帐户发送邮件的反馈页面

ruby-on-rails-3 - 我们可以使用精炼系统进行用户身份验证吗

ruby-on-rails - 如何验证 Rails 3 中没有属性?

ruby-on-rails - 虚拟属性和质量赋值

java - Heroku webapp-runner JNDI 命名,资源不可用

ruby-on-rails - 如何在 Rails 3 和 postgres 中处理大整数

python - 如何使用 rfc822msgid : 搜索电子邮件

java - GMail 将链接参数转换为错误的格式