Search code examples
symfonyemailsmtpsymfony4swiftmailer

Can't send E-Mails with symfony and swiftmailer using SMTP Server


when I try to send an e-Mail I get the error:

Exception occurred while flushing email queue: Connection could not be established with host w00d8ef1.kasserver.com [ #0]

.env

MAILER_URL=smtp://w00d8ef1.kasserver.com:25?encryption=ssl&auth_mode=login&username=myusername&password=mypassword

swiftmailer.yaml

swiftmailer:
    url: '%env(MAILER_URL)%'
    spool: { type: 'memory' }

Controller:

$message = (new Swift_Message('Test'))
    ->setFrom('info@lama.resper.de')
    ->setTo($user->getEmail())
    ->setBody(
        $this->renderView(
            'pdf/usercard.html.twig',
            ['user' => $user]
        ),
        'text/html'
    )
;
$mailer->send($message);

Hope someone can help me. The Mailserver is running.


Solution

  • Are you sure that you are using the right port number for smtp? Generally, it runs on 465 or 587. So, try to change the port number in your MAILER_URL env variable.