Rails 4 Net::SMTPAuthenticationError: 535 #5.7.0 Authentication failed

10,034

Solution 1

Try adding openssl_verify_mode => 'none' to your action mailer settings:

config.action_mailer.smtp_settings = 
{
    :address   => "smtp.school.edu",
    :port      => 25, 
    :enable_starttls_auto => true, 
    :user_name => "[email protected]",
    :password  => "mypassword", 
    :authentication => 'login',
    :domain => 'http://myapp.herokuapp.com/',
    :openssl_verify_mode => 'none'
}

Granted, we are using Rails 3, but this worked for me. The issue for us was that our certificates are self-signed and the library Rails uses considers that to be a problem. Here is an article that talks about the option.

Solution 2

Should ":domain" point to "school.edu" instead of "herokuapp.com"? I know when you set smtp for gmail via action_mailer settings, you have something like:

config.action_mailer.smtp_settings = {
    :address              => 'smtp.gmail.com',
    :port                 => 587,
    :domain               => 'gmail.com',
    :user_name            => '[email protected]',
    :password             => 'example_password',
    :authentication       => 'login',
    :enable_starttls_auto => true
  }

Solution 3

Create a file setup_mail.rb in the folder config/initializers/ and put the code:-

ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.smtp_settings = {
  :address   => "smtp.school.edu",
  :domain => 'myapp.herokuapp.com',
  :port      => 25,
  :user_name => "[email protected]",
  :password  => "mypassword", 
  :authentication => :plain,
  :enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "myapp.herokuapp.com"
Share:
10,034
Deekor
Author by

Deekor

Updated on June 04, 2022

Comments

  • Deekor
    Deekor almost 2 years

    I'm building a email list for a student organization at my University. The organization has around 6000 members and to avoid costs I've received permission to use the schools emails servers and they have created an account for me.

    I have tested the the account using my mail client and everything seems to be working fine, but when I try to send through my Rails 4 app I get the error:

    Net::SMTPAuthenticationError: 535 #5.7.0 Authentication failed
    

    I have it configured like so:

    application.rb

    config.action_mailer.smtp_settings = 
    {
        :address   => "smtp.school.edu",
        :port      => 25, 
        :enable_starttls_auto => true, 
        :user_name => "[email protected]",
        :password  => "mypassword", 
        :authentication => 'login',
        :domain => 'http://myapp.herokuapp.com/' 
    }
    

    Again the credentials are all correct, I have tested it through my mail client and have also sat down with the server admin to confirm everything looks right in my configuration as far as port and credentials.

    I've been told the smtp server is "wide open to the public" and there is nothing blocking a connection and we have checked their logs and they haven't even seen an attempt to connect from my app.

    Anyone have any clue what is going wrong here? Is there some setting I dont know about that could be off?

  • Deekor
    Deekor over 9 years
    Thanks for the suggestion, unfortunately I still get the same error message.
  • Deekor
    Deekor over 9 years
    hmmm doesnt seem to make a difference
  • user3334690
    user3334690 over 9 years
    Have you tried connecting to the smtp server using telnet or the like? That's how I figured out what was wrong with my configuration...
  • user3334690
    user3334690 over 9 years
    @Deekor hmm... do you think you could add what you did to connect via telnet to the question (scrubbed a bit of course)?
  • Deekor
    Deekor over 9 years
    how is this any different than what I am doing?
  • Deekor
    Deekor over 9 years
    domain shouldnt matter according to the server admin
  • Benjamin
    Benjamin almost 8 years
    Thank you for the answer, and the link to the reason. This helped me.