How to correctly configure symfony2 swiftmailer bundle to work with SMTP server with NTLM AUTH?
Asked Answered
I

2

1
# Swiftmailer Configuration
swiftmailer:
    transport:  smtp
    host:       10.8.100.1
    port:       25
    username:   user
    password:   pass
    auth_mode:  ~
    encryption: ~
    spool:      { type: memory }

When I try to send a message via $this->get('mailer')->send($message); I am getting the following error:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Failed
to authenticate on SMTP server with username "user" using 0 possible  authenticators'
in /..path../vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php:184 Stack trace: #0 

I've tried changeing the auth_mode setting to all possible values plain, login, cram-md5, or null - still the same error message.


Then I wanted to telnet to SMTP server to manually check if i can auth (though, I am 100% sure the credentials are correct).

telnet 10.8.100.1 25

Trying 10.8.100.1...
Connected to 10.8.100.1.
Escape character is '^]'.
220 EXC.acme.local Microsoft ESMTP MAIL Service ready at Wed, 19 Mar 2014 10:34:00 +0100

EHLO EXC.acme.local

250-EXC.acme.local Hello [10.8.100.1]
250-SIZE
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-STARTTLS
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS GSSAPI NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250 XRDST

I'm no mail server expert, but I was expecting AUTH LOGIN there... seems like the server (over which I have no control) has a diffrent authentication method (which is not suppoerted by Swiftmailer bundle?) and that might be the cause of the problem...

Are my suspictions correct? Or is there a way to configure Swiftmailer bundle to correctly auth with AUTH NTLM?

Impolicy answered 19/3, 2014 at 9:56 Comment(3)
just for information, is user the username and pass the password? I mean, are actually them?Lauer
no, they're diffrent, but obviously I can't disclose credential information here :)Impolicy
they are written in plain text (in the configuration), if that mattersImpolicy
I
0

So.. the problem wasn't with the symfony2 configuration. The problem was:

  • the mailbox was configured to work inside VPN (from computers in the domain/group)
  • I was trying to send a test mail from my development machine (while being connected to VPN... but my computer is not in the domain/group)

This is also the reason why telnet EXC.acme.local 25 didn't work, but telnet 10.8.100.1 25 did work.

So, when I tried to telnet, and then EHLO from my dev machine.. is got 250-AUTH NTLM, but when I SSH'ed to the prod machine (which is inside the domain/group) and telnet from there:

  • telnet EXC.acme.local 25 did work
  • EHLO EXC.acme.local returned AUTH LOGIN

Once I discovered that, I just uploaded my changes to prod machine and started testing the config from there (with swiftmailer.transport: smtp) and it worked!

Impolicy answered 19/3, 2014 at 13:10 Comment(0)
L
1

It seems that Mail Server refuse your connection (like google do, if you try to connect with your gmail account, if you have, and swiftmailer, you'll obtain the same issue)

Told that, why don't you try with Swift_MailTransport instead of Swift_SmtpTransport (it use mail underlying method that is a bit different of smtp)

Lauer answered 19/3, 2014 at 10:6 Comment(6)
it does not throw an error anymore... but so far, the test mail is not delivered (5 minutes)Impolicy
maybe mailserver accept it and ... discard. Try with unix mail system (if you can) and tell me if mail reach youLauer
the server admin sais there is nothing in the logs.. it does not even try to connect..Impolicy
it seems the mailserver refused connection, but for other reasonsImpolicy
If is mailserver issue, we cannot help you anymore :)Lauer
thanks for help @DonCallisto, in the end it was my fault (or lack of knowledge) - see my anwserImpolicy
I
0

So.. the problem wasn't with the symfony2 configuration. The problem was:

  • the mailbox was configured to work inside VPN (from computers in the domain/group)
  • I was trying to send a test mail from my development machine (while being connected to VPN... but my computer is not in the domain/group)

This is also the reason why telnet EXC.acme.local 25 didn't work, but telnet 10.8.100.1 25 did work.

So, when I tried to telnet, and then EHLO from my dev machine.. is got 250-AUTH NTLM, but when I SSH'ed to the prod machine (which is inside the domain/group) and telnet from there:

  • telnet EXC.acme.local 25 did work
  • EHLO EXC.acme.local returned AUTH LOGIN

Once I discovered that, I just uploaded my changes to prod machine and started testing the config from there (with swiftmailer.transport: smtp) and it worked!

Impolicy answered 19/3, 2014 at 13:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.