Rails App on Heroku Sending Email Error

末鹿安然 提交于 2019-12-22 12:20:25

问题


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?


回答1:


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".



来源:https://stackoverflow.com/questions/16422316/rails-app-on-heroku-sending-email-error

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