无法让 ActionMailer 通过 SMTP 与 MS Exchange 配合使用
这是我的简单测试程序(使用 ActionMailer 3.0.8、Ruby 1.9.2p180 Mac OS X):
require 'rubygems'
require 'action_mailer'
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "my_exchange_server",
:port => 25,
:domain => 'my_domain.org',
:authentication => :login,
:user_name => 'my_user',
:password => 'my_password',
:enable_starttls_auto => false
}
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default :from => 'from_email@my_company.com'
m = ActionMailer::Base.mail :to => 'to_email@my_company.com', :subject => 'this is a test', :body => 'this is a test'
m.deliver
尝试各种身份验证类型我收到以下错误:
:plain 错误:
smtp.rb:966:in `check_auth_response': 504 5.7.4 Unrecognized authentication type. (Net::SMTPAuthenticationError)
:login 错误:
smtp.rb:972:in `check_auth_continue': 504 5.7.4 Unrecognized authentication type. (Net::SMTPSyntaxError)
:cram_md5 错误:
smtp.rb:972:in `check_auth_continue': 504 5.7.4 Unrecognized authentication type. (Net::SMTPSyntaxError)
无身份验证错误:
protocol.rb:135:in `read_nonblock': end of file reached (EOFError)
有什么想法吗?
Here's my simple test program (using ActionMailer 3.0.8, Ruby 1.9.2p180 Mac OS X):
require 'rubygems'
require 'action_mailer'
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "my_exchange_server",
:port => 25,
:domain => 'my_domain.org',
:authentication => :login,
:user_name => 'my_user',
:password => 'my_password',
:enable_starttls_auto => false
}
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.default :from => 'from_email@my_company.com'
m = ActionMailer::Base.mail :to => 'to_email@my_company.com', :subject => 'this is a test', :body => 'this is a test'
m.deliver
Trying various authentication types I get the following errors:
:plain error:
smtp.rb:966:in `check_auth_response': 504 5.7.4 Unrecognized authentication type. (Net::SMTPAuthenticationError)
:login error:
smtp.rb:972:in `check_auth_continue': 504 5.7.4 Unrecognized authentication type. (Net::SMTPSyntaxError)
:cram_md5 error:
smtp.rb:972:in `check_auth_continue': 504 5.7.4 Unrecognized authentication type. (Net::SMTPSyntaxError)
No authentication error:
protocol.rb:135:in `read_nonblock': end of file reached (EOFError)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查启用了哪些身份验证方案
可能是:none、plain、login、cram_md5、NTLM、StartTLS
250-AUTH LOGIN
”或“250-AUTH=LOGIN
”表示您需要进行身份验证。250-AUTH
”(该行后面没有任何其他内容!)似乎表明您不应该验证自己的身份!否则你会得到错误:如何正确访问 Exchange
良好的资源,应该可以帮助您了解问题并对其进行故障排除。
如何您可以更改 Exchange 来解决问题
(而不是更改访问 Exchange 的方式)
Redmine 特定
对 Ruby on Rails 的帮助
Check what authentication schemes are enabled
It could be: none, plain, login, cram_md5, NTLM, StartTLS
250-AUTH LOGIN
" or "250-AUTH=LOGIN
" indicate that you need to authenticate.250-AUTH
" (with nothing else following on that line!) seems to indicate that you should NOT authenticate yourself! Otherwise you will get the error:How to properly access Exchange
Good resources that should help you to understand and troubleshoot it.
How you could change Exchange to fix the problem
(instead of changing how you access Exchange)
Redmine specific
Helpful for Ruby on Rails
有类似的网络问题。使用 irb 中的以下代码可以在控制台中获取调试信息。
从来没有真正发现问题是什么。他们移动了交换服务器,生产服务器停止发送电子邮件。我并不是真正的 IT 人员,但根据我所在网络的哪个部分,有不同的调试日志。最终通过发送未经身份验证的电子邮件“解决”了问题......
had similar network issues. use the code below in
irb
to get debug info right in the console.never really found out what the issue was. they moved the exchange server and the production server stopped sending emails. im not really an IT guy but there were different debug logs depending which part of the network i was on. finally "solved" the problem by sending unauthenticated email...
您可以连接到 SMTP 服务器并查询支持的身份验证方法:
服务器应响应至少一行以
250-AUTH
开头的行。之后列出了支持的身份验证方法。 Exchange 服务器可能仅支持通过 GSSAPI 或 NTLM 进行身份验证。在后一种情况下,您也许可以让它与 ruby-ntlm gem 和 ntlm 身份验证方法一起使用。 (请参阅 http://www.breckenedge .com/configuration-of-ruby-on-rails-actionmailer-for-microsoft-exchange-smtp)You could connect to the SMTP server and query the supported authentication methods:
The server should respond with at least one line that starts with
250-AUTH
. After that the supported authentication methods are listed. Chances are that the Exchange server only supports authentication via GSSAPI or NTLM. In the latter case you might be able to get it to work with the ruby-ntlm gem and thentlm
authentication method. (See http://www.breckenedge.com/configuration-of-ruby-on-rails-actionmailer-for-microsoft-exchange-smtp)