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.yaml
Content:
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粉4821083102024-02-18 10:29:56
Based on your current messenger configuration, the email is not sent directly, but only when messenger:consume
is called.
This is because Messenger is queuing the email (or other message like a text message) instead of sending it immediately.
You can learn more about the Message component here a>, but if you want to ignore it for now, just send emails synchronously by modifying the transport configuration.
framework: messenger: transports: async: '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