1

The answer to a previous question from 2012 indicates that the following should work to send out an email through Gmail.

require 'mail'

Mail.defaults do
  delivery_method :smtp, {
    address: "smtp.gmail.com",
    port: 587,
    user_name: <username>,
    password: <password>,
    authentication: :plain,
    enable_starttls_auto: true
  }
end

Mail.deliver do
  from    <email>
  to      <email>
  subject 'This is a test email'
  body    'body'
end

However, I tried it and I get

/home/<username>/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/net/smtp.rb:969:in `check_auth_response': 534-5.7.14 <https://accounts.google.com/ContinueSignIn?<url_parameters>(Net::SMTPAuthenticationError)
        from /home/<username>/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/net/smtp.rb:740:in `auth_plain'
        from /home/<username>/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/net/smtp.rb:732:in `authenticate'
        from /home/<username>/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/net/smtp.rb:567:in `do_start'
        from /home/<username>/.rvm/rubies/ruby-2.1.6/lib/ruby/2.1.0/net/smtp.rb:520:in `start'
        from /home/<username>/.rvm/gems/ruby-2.1.6/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
        from /home/<username>/.rvm/gems/ruby-2.1.6/gems/mail-2.6.3/lib/mail/message.rb:2141:in `do_delivery'
        from /home/<username>/.rvm/gems/ruby-2.1.6/gems/mail-2.6.3/lib/mail/message.rb:238:in `deliver'
        from /home/<username>/.rvm/gems/ruby-2.1.6/gems/mail-2.6.3/lib/mail/mail.rb:140:in `deliver'
        from mail.rb:14:in `<main>'

What is the modern way to get this to work. I've tried turning on access for less secure apps.

Community
  • 1
  • 1
user782220
  • 10,677
  • 21
  • 72
  • 135
  • Do you have two-factor authentication enabled on your gmail account? – polarcare Oct 25 '15 at 21:13
  • 2-step verification is off – user782220 Oct 25 '15 at 21:43
  • 2
    I had the same thing happen to me after years of the code working just fine... Try going into your Google account's security settings and "verify" the request. Once verified, the location should be recognized as "safe" and access granted. Google forces 2 step verification, even when disabled, for "suspicious" logins... good luck! – Myst Oct 25 '15 at 21:59
  • @Myst So I looked at the security UI and couldn't find anything mentioning verify. Where are you looking at? – user782220 Oct 25 '15 at 22:14
  • Oh wait somehow I got it to work – user782220 Oct 25 '15 at 22:20

0 Answers0