I have an issue with using swiftmailer with the client's SMTP microsoft exchange server.
To troubleshoot, I am thinking of changing out the swiftmailer with something else.
My entire setup is on an internal network. So no mailgun or sendgrid at all.
How do I use an alternative library for swiftmailer in Laravel in order to troubleshoot?
Also this is the log I get when I tried to use swiftmailer on Laravel
<< 250-xxx.internal.abc.com Hello [xxx.xx.xxx.xx]
250-SIZE 36700160
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-AUTH
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250-XEXCH50
250 XSHADOW
>> STARTTLS
<< 500 5.3.3 Unrecognized command
!! Expected response code 220 but got code "500", with message "500 5.3.3 Unrecognized command
Somebody asked me to try MAIL_ENCRYPTION to null and dd(config('mail.encryption')), so the below is the answer:
Code:
try {
Mail::send('emails.test', [], function ($m) {
$m->from('[email protected]', 'Your Application')->to('[email protected]');
dd(config('mail.encryption'));
var_dump('executed');
});
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
}
Result:
null
was printed out The string executed
was not.
explicitly use swiftmailer transport with encryption set to null
try {
// Create the Transport
$transport = \Swift_SmtpTransport::newInstance();
$transport->setUsername('[email protected]')
->setPort(25)
->setHost('smtp.internal.client.com')
->setEncryption(null);
// Create the Mailer using your created Transport
$mailer = \Swift_Mailer::newInstance($transport);
$logger = new \Swift_Plugins_Loggers_ArrayLogger();
$mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($logger));
$message = new \Swift_Message('Wonderful Subject');
$message->setFrom(['[email protected]' => 'John Doe']);
$message->setTo(['[email protected]'])->setBody('Here is the message itself');
// // Send the message
$numSent = $mailer->send($message);
} catch(\Swift_TransportException $e) {
var_dump('test');
var_dump($e->getMessage());
var_dump($e->getTraceAsString());
}
Result:
www-data@server:~/html/laravel-app$ php artisan email:send
string(4) "test"
string(127) "Failed to authenticate on SMTP server with username "[email protected]" using 0 possible authenticators"
string(2503) "#0 /var/www/html/a3qp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php(332): Swift_Transport_Esmtp_AuthHandler->afterEhlo(Object(Swift_SmtpTransport))
Same as part II but set encryption to 'tls' explicitly. I get the same error message as the original one at the very top.
Someone asked me to take out the dd line in Part I This is what I got
string(8) "executed"
[Swift_TransportException]
Failed to authenticate on SMTP server with username "[email protected]" using 0 possible authenticators
Update
You can use the Mail::failures() function for that.
The SMTP server you're attempting to connect to does not understand the STARTTLS
command. To prevent the STARTTLS
command from being attempted, you must disable encryption by setting your MAIL_ENCRYPTION
environment variable to null
in your .env
file.
The next issue is that, according to the EHLO
response, the SMTP server does not accept any authentication methods. If it did, the line 250-AUTH
would also include the methods it accepted (e.g. 250-AUTH PLAIN DIGEST-MD5
).
To prevent an authentication attempt, you must set your MAIL_USERNAME
environment variable to null
in your .env
file.
To sum up, your .env
file should have the following lines:
MAIL_ENCRYPTION=null
MAIL_USERNAME=null
That will disable tls encryption and disable authentication.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With