Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get ActionMailer working with MS Exchange via SMTP

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?

like image 894
Edward J. Stembler Avatar asked Jun 29 '11 15:06

Edward J. Stembler


1 Answers

Check what authentication schemes are enabled

It could be: none, plain, login, cram_md5, NTLM, StartTLS

  • Using Telnet to connect to Exchange 2003 POP3 mailboxes and using SMTP to send e-mail for troubleshooting purposes
    • http://www.msexchange.org/tutorials/telnet-exchange2003-pop3-smtp-troubleshooting.html
      • Scroll down to: Connecting to SMTP
      • What did EHLO return?
        • "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:
          • "504 5.7.4 Unrecognized authentication type"

How to properly access Exchange

Good resources that should help you to understand and troubleshoot it.

  • The EHLO verb and SMTP extensions
    • http://cr.yp.to/smtp/ehlo.html
  • The AUTH Command
    • http://www.samlogic.net/articles/smtp-commands-reference-auth.htm
  • How to Use Telnet to Send SMTP Email to Exchange 2007 and 2010
    • http://www.expta.com/2010/03/how-to-use-telnet-to-send-smtp-email-to.html
  • Using telnet to test authenticated relay in Exchange
    • http://www.dasblinkenlichten.com/?p=190

How you could change Exchange to fix the problem

(instead of changing how you access Exchange)

  • How to enable auth login on smtp server exchange 2010
    • http://www.experts-exchange.com/Software/Server_Software/Email_Servers/Exchange/Q_26538583.html
  • How to Enable "Auth Login" authenticaton on Exchange
    • http://www.advancedintellect.com/post/2011/03/02/Exchange-2010-and-SMTP-settings.aspx
  • Error in establishing SMTP connection, Error: 504 5.7.4 Unrecognized authentication type
    • (how to change the Exchange 2010 configuration to "accept mail from third part product" as mentioned by Anil K Singh)
      • http://social.technet.microsoft.com/Forums/en-US/exchange2010/thread/93ad411a-0da2-4494-a45e-8cbb793aeca9/

Redmine specific

Helpful for Ruby on Rails

  • How to configure Redmine to mail to MS Exchange server
    • http://www.redmine.org/projects/redmine/wiki/HowTo_configure_Redmine_to_mail_to_MS_Exchange_server
      • "MS Exchange will not require authentication information for outgoing (SMTP) email"
      • My configuration file is still at config/email.yml (in Redmine 1.2)
  • Helpful troubleshooting tips for Ruby on Rails code
    • See answer from firien
  • How to use ruby-ntlm in case Exchange requires NTLM
    • Unrecognized authentication type when doing an Auth to Exchange from Rails
  • How to use the TLS option
    • http://www.redmineblog.com/articles/setup-redmine-to-send-email-using-gmail/
like image 135
E. Sambo Avatar answered Oct 26 '22 19:10

E. Sambo