问题
# 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?
回答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
)
回答2:
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 workEHLO 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!
来源:https://stackoverflow.com/questions/22502058/how-to-correctly-configure-symfony2-swiftmailer-bundle-to-work-with-smtp-server