I am using Rails Mailer and Gmail to send emails. But I keep getting the Net::SMTPAuthenticationError 535-5.7.8 Username and Password not accepted
error.
I checked out other questions regarding this problem but unfortunately, they didn't help.
I have a 2-step authentication enabled and I did create the App Password for my Rails app.
This is my configuration in production.rb
:
config.action_mailer.perform_caching = false
config.action_mailer.delivery_method = :smtp
host = 'myhost'
config.action_mailer.default_url_options = { host: host }
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
domain: 'myhost',
port: 587,
user_name: 'myemail@domain.com',
password: ENV['GMAIL_APP_PASSWORD'],
authentication: 'plain',
enable_starttls_auto: true
}
Now, it is worth noting that I am using a non-Gmail address but I am using GSuite which allows me to log in to Gmail with that address and use it pretty much as a Gmail address.
If it means anything, after trying to send an email with Rails I did receive an email about Blocked login alert. And to note again, I am using the App Password, not the general password for the account.
Seen some answers saying that I have to enable less secure apps option but I can't enable it while 2-step is active.
Have you allowed for less secure apps? Please do so, and see if that helps. Less secure apps
If using 2 Step Verification in Gmail, you may need an application password. Create & use App Passwords
If it still doesnt work you may need to consider checking xoauth2-protocol