简体   繁体   English

Symfony 6 邮件 DSN SMTP 不发送邮件

[英]Symfony 6 mailer DSN with SMTP doesn't send mails

I'm trying Symfony 6 Mailer with different SMTP servers and none of them is working.我正在尝试使用不同的 SMTP 服务器的 Symfony 6 Mailer,但它们都无法正常工作。

The messages are queued but not sent.消息已排队但未发送。 I tried from different servers to discard a firewall or port issue.我尝试从不同的服务器丢弃防火墙或端口问题。

There are no log messages or exceptions, so I'm quite lost.没有日志消息或异常,所以我很迷茫。

This are some DSN I tried:这是我试过的一些 DSN:

MAILER_DSN="smtp://email%40example.com:123456@host.example.com:587?encryption=tls"
MAILER_DSN="smtp://email@example.com:123456@host.example.com:587?encryption=tls"
MAILER_DSN="smtp://email@example.com:123456@host.example.com:587"

I actually tried many DSN combinations with/without encryption.我实际上尝试了很多带/不带加密的 DSN 组合。 I suspect the problem is in the DSN string as, if I try wrong hosts or passwords, the effect is the same.我怀疑问题出在 DSN 字符串中,因为如果我尝试错误的主机或密码,效果是一样的。

This is a long lasting problem I haven't been able to resolve in a long time.这是一个长期存在的问题,我很长一段时间都无法解决。

And 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: mailer.yaml内容:

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

And messenger.yaml content:messenger.yaml内容:

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

With your current messenger configuration, emails are not sent directly, but only when messenger:consume is called.使用您当前的 Messenger 配置,不会直接发送电子邮件,而是仅在调用messenger:consume时发送。

That's because messenger is queuing emails (or other messages such as SMS) instead of being immediately sent.这是因为 Messenger 正在排队电子邮件(或其他消息,例如 SMS),而不是立即发送。

You can learn more about the messenger component here , but if you want to ignore it for now and just send your emails synchronously by modifying your transport configuration.您可以在此处了解有关 Messenger 组件的更多信息,但如果您想暂时忽略它并通过修改您的传输配置来同步发送您的电子邮件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM