2015-02-23 46 views
0

我在我的项目中设置邮件程序,并且无法通过Exchange SMTP服务器发送邮件。Ruby/Rails ActionMailer不适用于NTLM

我已经安装了gem ruby-ntlm,但我仍然得到unrecognized authentication type

这是我的代码

的environment.rb

# Load the Rails application. 
require File.expand_path('../application', __FILE__) 
require 'ntlm/smtp' 

# Initialize the Rails application. 
Rails.application.initialize! 

notifier.rb

class Notifier < ActionMailer::Base 
    default :from => "[email protected]" 

    def test 
    mail(:to => "[email protected]", :subject => "Test subject").deliver 
    end 
end 

development.rb

config.action_mailer.delivery_method = :smtp 
    config.action_mailer.smtp_settings = { 
    :address => "**REMOVED**", 
    :port => 587, 
    :domain => "CMSAD", 
    :user_name => "**REMOVED**", 
    :password => "**REMOVED**", 
    :authentification => :ntlm, 
    :enable_starttls_auto => false 
    } 

Rails的控制台测试

Notifier#test: processed outbound mail in 5591.8ms 
Net::SMTPAuthenticationError: 504 5.7.4 Unrecognized authentication type 

     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:968:in `check_auth_response' 
     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:739:in `auth_plain' 
     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:731:in `authenticate' 
     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:566:in `do_start' 
     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/2.1.0/net/smtp.rb:519:in `start' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/mail-2.6.3/lib/mail/message.rb:2141:in `do_delivery' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/mail-2.6.3/lib/mail/message.rb:236:in `block in deliver' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/actionmailer-4.1.8/lib/action_mailer/base.rb:527:in `block in deliver_mail' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/notifications.rb:159:in `block in instrument' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/notifications.rb:159:in `instrument' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/actionmailer-4.1.8/lib/action_mailer/base.rb:525:in `deliver_mail' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/mail-2.6.3/lib/mail/message.rb:236:in `deliver' 
     from /media/development/Foostix-web/app/mailers/notifier.rb:5:in `test' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/actionpack-4.1.8/lib/abstract_controller/base.rb:189:in `process_action' 
... 15 levels... 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:9:in `start' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:69:in `console' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `block in require' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:247:in `require' 
     from /media/development/Foostix-web/bin/rails:8:in `<top (required)>' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `block in load' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:232:in `load_dependency' 
     from /home/stephen/.rvm/gems/ruby-2.1.0/gems/activesupport-4.1.8/lib/active_support/dependencies.rb:241:in `load' 
     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require' 
     from /home/stephen/.rvm/rubies/ruby-2.1.0/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:54:in `require' 

但是这个工程....

smtp = Net::SMTP.new('**REMOVED**', 587) 
smtp.debug_output = $stdout 
smtp.enable_starttls_auto#skip if not needed 
smtp.start("CMSAD", "**REMOVED**", "**REMOVED**", :ntlm) 

TLS connection started 
<- "EHLO CMSAD\r\n" 
-> "250-**REMOVED** Hello [**REMOVED**]\r\n" 
-> "250-SIZE 104857600\r\n" 
-> "250-PIPELINING\r\n" 
-> "250-DSN\r\n" 
-> "250-ENHANCEDSTATUSCODES\r\n" 
-> "250-AUTH GSSAPI NTLM LOGIN\r\n" 
-> "250-8BITMIME\r\n" 
-> "250-BINARYMIME\r\n" 
-> "250 CHUNKING\r\n" 
<- "AUTH NTLM **REMOVED**==\r\n" 
-> "334 **REMOVED**\r\n" 
<- **REMOVED**\r\n" 
-> "235 2.7.0 Authentication successful\r\n" 
=> #<Net::SMTP **REMOVED** started=true> 

回答

0

这是因为你还没有包括ntlm库。

的NTLM SMTP库添加到您的config/environment.rb文件

# Load the Rails application. 
require File.expand_path('../application', __FILE__) 

require 'ntlm/smtp' # ADD THIS LINE HERE 

# Initialize the Rails application. 
Rails.application.initialize! 
+0

这已经对不起,我忘了发布environment.rb – 2015-02-23 12:44:38

+0

我编辑原始帖子与环境。rb – 2015-02-23 12:46:13

0

添加ruby-ntlm gemGemfile和运行bundle install

的Gemfile:

gem 'ruby-ntlm' 

bundle install

的NTLM SMTP库添加到您的config/environment.rb文件。

# Load the rails application 
require File.expand_path('../application', __FILE__) 
require 'ntlm/smtp' 

# Initialize the rails application 
RailsApp::Application.initialize! 

设置您的环境文件以使用NTLM进行身份验证。

config.active_support.deprecation = :notify 
config.action_mailer.delivery_method = :smtp 
config.action_mailer.smtp_settings = { 
    :address => '<your-email-server>',   # mail.example.com 
    :domain => '<your-domain>',     # example.com 
    :user_name => '<your-username>',   # user.name 
    :password => '<your-unencrypted-password>', # [email protected] 
    :port => 25, 
    :authentication => :ntlm 
} 

最后,确保你无论从任何电子邮件地址,您一直在使用,以反映新的Microsoft Exchange帐户更改默认的,或者您会收到一个5.7.1客户端没有权限来发送,因为这发件人错误。

+0

ruby​​-ntlm已经在environment.rb中安装并初始化了(我更新了原文,对不起) – 2015-02-23 12:47:52

+0

清楚地检查我的文章/你犯了很多错误::authentification =>:ntlm,'也是'port'' 587 '它应该是'25' – 2015-02-24 13:25:44

0

发现错字,现在正在工作!

development.rb

变化:authentification => :ntlm:authentication => :ntlm

感谢反正支持!

相关问题