Search code examples
ruby-on-railsrubyemailsmtpgmail-imap

Sending an email in Rails


I'm trying to send an email using Ruby on Rails but I get the error:

Net::SMTPAuthenticationError in UsersController#create

535-5.7.1 Username and Password not accepted.


But the username and password combination is correct. I've gone through it multiple times.

This is my setup_mail.rb:
I changed the username, password and domain for privacy reasons.

ActionMailer::Base.smtp_settings = { 
    :address            => "smtp.gmail.com",
    :port               => 587,
    :domain             => "mydomain.com",
    :authentication     => "plain",
    :user_name          => "myname",
    :password           => "mypw",
    :enable_starttls_auto   => true
}

Solution

  • Your username has to be

    :user_name => "myname@mydomain.com"
    

    For gmail the domain is required.