Erik
Erik

Reputation: 305

Can I authenticate SMTP using SwiftMailer without sending an email

I am trying to verify login credentials with SwiftMailer in Laravel. I need to verify the login credentials to an SMTP server without actually sending the email.

I am trying to do something like this:

$client = Swift_SmtpTransport::newInstance($smtpServer, $smtpPort, 'ssl');
$client->setUsername($this->smtpUser);
$client->setPassword($this->smtpPass);
$client->authenticate();

There is no authenticate() method on the Swift_SmtpTransport but it would be great if there was something similar I could use.

I can't find a suitable function in the source: https://github.com/swiftmailer/swiftmailer/blob/master/lib/classes/Swift/Transport/AbstractSmtpTransport.php

Is there a way to just try and verify authentication on an SMTP server using SwiftMailer without having to send the email?

Upvotes: 4

Views: 2058

Answers (1)

uri2x
uri2x

Reputation: 3202

From their manual:

If you need to know early whether or not authentication has failed and an Exception is going to be thrown, call the start() method on the created Transport.

Upvotes: 5

Related Questions