Search code examples
ruby-on-rails-3herokugmail

Rails App on Heroku Sending Email Error


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: "[email protected]",
     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 [email protected] (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?


Solution

  • 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 "[email protected]".