[英]Unable to send email via SMTP over SSL using cram_md5 authentication
I am writing a Ruby script to send email using the 'mail' gem. 我正在编写一个Ruby脚本,以使用“邮件” gem发送电子邮件。
These are my SMTP settings on my local machine: 这些是我在本地计算机上的SMTP设置:
mailer_options:
address: smtp.gmail.com
port: 465
domain: gmail.com
user_name: example@gmail.com
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: 当我尝试使用上述SMTP设置发送电子邮件时,出现以下异常:
/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 我尝试搜索此错误并发现
SASL LOGIN authentication failed: Invalid authentication mechanism on Rails using Postfix and Dovecot on Ubuntu 12.10 SASL登录身份验证失败:在Ubuntu 12.10上使用Postfix和Dovecot在Rails上使用无效的身份验证机制
but it does not help. 但这无济于事。
Why are you using MD5? 为什么要使用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. 如果您使用的是TLS(SSL),则不需要这样做,因为连接本身是加密的,甚至Base64编码的密码也是安全的。
When you connect to a server it will advertise what authentication types are allowed. 当您连接到服务器时,它将通告允许的身份验证类型。 In the case of Google Gmail the header looks like: 对于Google Gmail,标题如下:
250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 PLAIN-CLIENTTOKEN
CRAM-MD5
is not supported. 不支持CRAM-MD5
。 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. Google可能放弃了MD5,因为考虑到破解MD5的难易程度,该方法几乎无法提供安全性。
You won't be able to authenticate to Gmail using cram_md5
. 您将无法使用cram_md5
向Gmail进行身份验证。 Here is an example configuration for using Gmail: 这是使用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 来源: https : //github.com/mikel/mail/wiki/Sending-email-via-Gmail-SMTP
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.