Ruby sending mail via gmail smtp
If you're not using 2 Factor Authentication
Go to this link:
https://www.google.com/settings/security/lesssecureapps
And select:
"Access for less secure apps"
as per:
https://support.google.com/accounts/answer/6010255?hl=en
In this case you would use your normal email and password to connect.
If you are using 2 Factor Authentication
You need to create an app specific password for your application. Follow these steps:
- Go to gmail
- in the top right corner click on your profile icon and select 'My Account'
- Click on 'Sign in & Security'
- Scroll down the 'Sign in & Security' page a bit and there is a section called 'App Passwords' Click on that.
- You should see a dropdown labelled 'Select App'. Select Mail.
- For the 'on my device' dropdown select 'Other' and type in commandline or whatever you want to call the app.
Click 'Generate'. A password will be generated. Copy that password and replace the password you were using in your options hash with the generated password:
options = { :address => "smtp.gmail.com", :port => 587, :user_name => '', :password => '', :authentication => 'plain', :enable_starttls_auto => true }
That should be it. I just tried this and it worked for me.
Also make sure your username is your full gmail email address.
You can also find the 'Official docs' here: https://support.google.com/accounts/answer/185833?hl=en