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.