search

Home  >  Q&A  >  body text

Symfony 6 mail sender DSN using SMTP cannot send mail

I'm trying to use Symfony 6 Mailer with different SMTP servers, but none of them work.

The message was queued but not sent. I've tried troubleshooting firewall or port issues from different servers.

There are no log messages or exceptions, so I'm confused.

Here are some DSNs I've tried:

MAILER_DSN="smtp://email%40example.com:[email protected]:587?encryption=tls"
MAILER_DSN="smtp://[email protected]:[email protected]:587?encryption=tls"
MAILER_DSN="smtp://[email protected]:[email protected]:587"

I actually tried many DSN combinations with/without encryption. I suspect the problem is in the DSN string because if I try the wrong host or password the effect is the same.

This is a long-standing problem that I couldn't solve for a long time.

This is the sending code:

use Symfony\Component\Mime\Email;

$email = (new Email())
        ->from($this->parameterBag->get('app.message.email_from'))
        ->to($to)
        ->subject($subject)
        ->text($text)
        ->html($text);

$sentMessage = $this->mailer->send($email);

mailer.yamlContent:

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

and messenger.yaml Content:

framework:
    messenger:
        failure_transport: failed

        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    use_notify: true
                    check_delayed_interval: 60000
                retry_strategy:
                    max_retries: 3
                    multiplier: 2
            failed: 'doctrine://default?queue_name=failed'
            # sync: 'sync://'

        routing:
            Symfony\Component\Mailer\Messenger\SendEmailMessage: async
            Symfony\Component\Notifier\Message\ChatMessage: async
            Symfony\Component\Notifier\Message\SmsMessage: async

            # Route your messages to the transports
            # 'App\Message\YourMessage': async

P粉957661544P粉957661544314 days ago336

reply all(1)I'll reply

  • P粉482108310
  • Cancelreply