简体   繁体   English

无法使用cram_md5身份验证通过SMTP通过SMTP发送电子邮件

[英]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.

相关问题 gitlab无法通过smtp发送电子邮件 - gitlab can not send email via smtp 在 Rails 3 和 ActionMailer 中,是否可以通过 SSL(不是 StartTLS)使用 TLS 发送 email? - In Rails 3 and ActionMailer, is it possible to send email using TLS over SSL (Not StartTLS)? 配置Rails以通过Microsoft LiveSMTP服务器发送电子邮件 - configuring rails to send email via the microsoft live smtp server 如何使用SMTP服务器发送电子邮件? - How to send email using SMTP server? Rails Mailboxer-通过smtp发送电子邮件时找不到收件人域 - Rails Mailboxer - unable to find the recipient domain on sending email via smtp Sendgrid通过Devise:在使用Cloud 9开发环境时,尝试发送身份验证电子邮件会导致OpenTimeout错误 - Sendgrid via Devise: Attempt to send authentication email leads to OpenTimeout error when using Cloud 9 dev environment 将SMTP电子邮件从其他电子邮件发送到smtp服务器导轨 - Send SMTP email from different email to smtp server rails 无法在生产环境中使用Action Mailer发送电子邮件 - Unable to send email using Action Mailer in production 使用SMTP通过ActionMailer :: Base发送电子邮件,但发件人应该是另一个电子邮件地址 - Sending Email via ActionMailer::Base using SMTP, but sender should be another email-adress 即使没有在同一台计算机上使用不带SSL / TLS的SMTP发送电子邮件也不安全吗? - Is Sending Email using SMTP without SSL/TLS insecure even if its in the same computer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM