I'm creating a ruby script that checks the response status of an url and if it equals with 504, it sends a mail to another email address. For some reason, I get this: /usr/lib/ruby/1.9.1/net/smtp.rb:960:in 'check_auth_response': 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbv9z (Net::SMTPAuthenticationError)
I quadra checked the authentication data and they are valid. Maybe there can be something wrong in the code:
require 'mail'
options = { :address => "smtp.gmail.com",
:port => 587,
:user_name => '<myusername>',
:password => '<mypassword>',
:authentication => 'plain',
:enable_starttls_auto => true }
Mail.defaults do
delivery_method :smtp, options
end
Mail.deliver do
to '[email protected]'
from '[email protected]'
subject 'Test'
body 'Hurray!!! Test email!'
end
Oh also, I got the notice from google that a less secure app tried to access my account, so I set up that less secure apps can use my account.
Use the Gmail SMTP serverIf you connect using SSL or TLS, you can send mail to anyone inside or outside of your organization using smtp.gmail.com as your server. This option requires you to authenticate with your Gmail or Google Workspace account and passwords.
Go to the config folder of your emails project and open environment. rb file and add the following line at the bottom of this file. It tells ActionMailer that you want to use the SMTP server. You can also set it to be :sendmail if you are using a Unix-based operating system such as Mac OS X or Linux.
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.
You need to create an app specific password for your application. Follow these steps:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With