Configuration of Ruby On Rails ActionMailer for Microsoft Exchange SMTP

You may find that your Microsoft Exchange server is not configured for AUTH LOGIN over STMP, and only supports the Microsoft-specific AUTH NTLM. When trying to use the default Net/SMTP library with an AUTH NTLM server, you’ll receive the 5.7.4 unrecognized authentication type error. Thanks to the ruby-ntlm¬†gem, you can still authenticate.

Steps

  1. Add the ruby-ntlm gem to your Gemfile and run bundle install.
  2. Add the NTLM SMTP library to your config/environment.rb file.
    # Load the rails application
    require File.expand_path('../application', __FILE__)

    require 'ntlm/smtp'

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

  3. Set up your environment file to authenticate with 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>', # p@ssw0rd
      :port => 25,
      :authentication => :ntlm
    }
  4. Finally, make sure you change your default from whatever email address you’ve been using to reflect the new Microsoft Exchange account, or you’ll receive a 5.7.1 Client does not have permissions to send as this sender error.