title: Ruby/Rails ActionMailer not working with NTLM
body: <p>I am setting up a mailer in my project and I am having difficulties sending mail through Exchange SMTP server.</p>
  
  <p>I have installed the gem <code>ruby-ntlm</code> but I am still getting <code>unrecognized authentication type</code>.</p>
  
  <p>This is my code</p>
  
  <p><strong>environment.rb</strong></p>
  
  <pre><code># Load the Rails application.
  require File.expand_path('../application', __FILE__)
  require 'ntlm/smtp'
  
  # Initialize the Rails application.
  Rails.application.initialize!
  </code></pre>
  
  <p><strong>notifier.rb</strong></p>
  
  <pre><code>class Notifier &lt; ActionMailer::Base
    default :from =&gt; "stephen.edwards@foostix.lu"
  
    def test
      mail(:to =&gt; "stephen.edwards@foostix.lu", :subject =&gt; "Test subject").deliver
    end
  end
  </code></pre>
  
  <p><strong>development.rb</strong></p>
  
  <pre><code>  config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = {
      :address =&gt; "**REMOVED**",
      :port =&gt; 587, 
      :domain =&gt; "CMSAD",   
      :user_name =&gt; "**REMOVED**", 
      :password =&gt; "**REMOVED**", 
      :authentification =&gt; :ntlm,
      :enable_starttls_auto =&gt; false
    }
  </code></pre>
  
  <p><strong>Rails console test</strong></p>
  
  <pre><code>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 `&lt;top (required)&gt;'
          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 `&lt;top (required)&gt;'
          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'
  </code></pre>
  
  <p><strong>However this works....</strong></p>
  
  <pre><code>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
  &lt;- "EHLO CMSAD\r\n"
  -&gt; "250-**REMOVED** Hello [**REMOVED**]\r\n"
  -&gt; "250-SIZE 104857600\r\n"
  -&gt; "250-PIPELINING\r\n"
  -&gt; "250-DSN\r\n"
  -&gt; "250-ENHANCEDSTATUSCODES\r\n"
  -&gt; "250-AUTH GSSAPI NTLM LOGIN\r\n"
  -&gt; "250-8BITMIME\r\n"
  -&gt; "250-BINARYMIME\r\n"
  -&gt; "250 CHUNKING\r\n"
  &lt;- "AUTH NTLM **REMOVED**==\r\n"
  -&gt; "334 **REMOVED**\r\n"
  &lt;- **REMOVED**\r\n"
  -&gt; "235 2.7.0 Authentication successful\r\n"
   =&gt; #&lt;Net::SMTP **REMOVED** started=true&gt;
  </code></pre>