我可以在不发送电子邮件的情况下使用SwiftMailer验证SMTP吗?


Can I authenticate SMTP using SwiftMailer without sending an email

我正在尝试验证登录凭证与SwiftMailer在Laravel。我需要验证SMTP服务器的登录凭据,而不实际发送电子邮件。

我正在尝试做这样的事情:

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

Swift_SmtpTransport上没有authenticate()方法,但如果有类似的方法可以使用,那就太好了。

我在源代码中找不到合适的函数:https://github.com/swiftmailer/swiftmailer/blob/master/lib/classes/Swift/Transport/AbstractSmtpTransport.php

是否有一种方法,只是尝试和验证身份上的SMTP服务器使用SwiftMailer而不必发送电子邮件?

从他们的手册:

如果您需要尽早知道身份验证是否失败和异常将被抛出,则调用start()方法创建运输。