I'm struggling a bit with the Symfony Mailer in combination with Exchange Server 2016.
As I was trying things out, I have found that Swift Mailer has native NTML support, but it gave me this error message which I was not able to overcome.
PHP Fatal error: Uncaught Swift_TransportException: Failed to authenticate on SMTP server with username "domain\username" using 1 possible authenticators. Authenticator NTLM returned Expected response code 235 but got code "535", with message "535 5.7.3 Authentication unsuccessful
Then I saw on the Swift Website this message:
Please, move to Symfony Mailer at your earliest convenience. Symfony Mailer is the next evolution of Swift Mailer. It provides the same features with support for modern PHP code and support for third-party providers.
I installed Symfony Mailer but noticed that it doesn't support NTML. Someone ported the NtmlAuthenticator.php
from Swift Mailer to Symfony Mailer. I have tried to implement this but can't figure out how this NtmlAuthenticator needs to be implemented.
It gives me
PHP Fatal error: Uncaught Error: Class "NtlmAuthenticator" not found in /var/www/cfs-tools/App/mailtest.php:15
Here is my code:
<?php
require '../vendor/autoload.php';
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\File;
use Symfony\Component\Mailer\Transport\Smtp\Auth\AuthenticatorInterface;
$transport = (new Symfony\Component\Mailer\Transport\Smtp\EsmtpTransport
('smtp.testdomain.com', 25))
->setUsername('testdomain\testemail')
->setPassword('password')
->setAutoTls(false);
$transport->setAuthenticators([new NtlmAuthenticator()]);
$mailer = new Mailer($transport);
$email = (new Email())
->from('testemail@testdomain.com')
->to("testemail@test.com")
->subject('Test Mail Subject')
->html('<p>Test Email Symfony</p>');
$mailer->send($email);
My setup: PHP 8.2.13
Exchange Server 2016
symfony/mailer 7.2.0
You didn't import NtlmAuthenticator()
.
I don't know the full path to it, you should find it in the docs of the package or you can inspect it in the composer.json in the vendor dir.
Should look like something like use Vendor\NtlmAuthenticator;\