I need to change the sending domain on some emails sent from Laravel. To do so, I have set up a queued job, and the in handle method configure the Swift_SmtpTransport
object as described here: Laravel Mail Queue: change transport on fly
public function handle(Mailer $mailer)
{
$transport = new \Swift_SmtpTransport(config('mail.host'), config('mail.port'), config('mail.encryption'));
$transport->setUsername(config('mail.username'));
$transport->setPassword(config('mail.password'));
$transport->setLocalDomain(env('MAILGUN_EMAIL_DOMAIN'));
$smtp = new \Swift_Mailer($transport);
$mailer->setSwiftMailer($smtp);
$mailer->send('emails.email', ['data'], function ($m) {
$m->setTo($this->to)
->setBody($this->email->emailResponse)
->setSubject(sprintf('%s [Ref: #%s]', $this->email->emailThread->subject, $this->email->emailThread->slug));
});
}
For some reason Mailgun doesn't like my login details.
When I send an email via the Mail facade, it works, so my logins are correct.
Failed to authenticate on SMTP server with username "xxx" using 2 possible authenticators. Authenticator LOGIN returned Swift_TransportException: Expected response code 235 but got code "535", with message "535 5.7.0 Mailgun is not loving your login or password
" in /home/vagrant/code/myapp/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:457
In mail.php
I have:
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
What gives?