Reputation: 7225
I am writing a Ruby script to send email using the 'mail' gem.
These are my SMTP settings on my local machine:
mailer_options:
address: smtp.gmail.com
port: 465
domain: gmail.com
user_name: [email protected]
password: example_password
authentication: :cram_md5
enable_starttls_auto: true
ssl: true
When I try to send email with the above SMTP settings, I get the following exception:
/opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:968:in `check_auth_continue': 504 5.7.4 Unrecognized Authentication Type ka3sm12016635pbc.32 - gsmtp (Net::SMTPSyntaxError)from /opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:758:in `block in auth_cram_md5from /opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:941:in `critical'
from /opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:756:in `auth_cram_md5'
from /opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:731:in `authenticate'
from /opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:566:in `do_start'
from /opt/rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/net/smtp.rb:519:in `start'
from /opt/rtpg/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
from /opt/rtpg/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:2129:in `do_delivery'
from /opt/rtpg/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/message.rb:234:in `deliver'
from /opt/rtpg/vendor/bundle/ruby/2.0.0/gems/mail-2.5.4/lib/mail/mail.rb:140:in `deliver'
I tried searching for this error and found
but it does not help.
Upvotes: 2
Views: 4986
Reputation: 13354
You won't be able to authenticate to Gmail using cram_md5
. Here is an example configuration for using Gmail:
Mail.defaults do
delivery_method :smtp, {
:address => 'smtp.gmail.com',
:port => '587',
:user_name => ENV['GMAIL_SMTP_USER'],
:password => ENV['GMAIL_SMTP_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
end
Source: https://github.com/mikel/mail/wiki/Sending-email-via-Gmail-SMTP
Upvotes: 2
Reputation: 211610
Why are you using MD5? If you're using TLS (SSL) you won't need to do this because the connection itself is encrypted and even a Base64 encoded password is secure.
When you connect to a server it will advertise what authentication types are allowed. In the case of Google Gmail the header looks like:
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
CRAM-MD5
is not supported. All the others are.
Google's probably dropped MD5 because that method provides little in the way of security given how easily cracked MD5 is.
Upvotes: 5