【问题标题】:Problems integrating Postmark with Symfony Mailer将 Postmark 与 Symfony Mailer 集成的问题
【发布时间】:2021-12-27 10:20:23
【问题描述】:

我目前正在努力尝试将 Postmark 与 Symfony5 Mailer Bundle 一起使用。虽然文档似乎很清楚,但我无法发送任何电子邮件。

我的第一个困惑点是建议的邮戳 DSN 格式:

邮戳+smtp://ID@default

似乎不清楚应该使用什么 ID,因为 SMTP 的 Postmark 提供了用户名和密码,以及访问密钥和秘密密钥(SMTP 令牌)。未按要求提供 ID。

有人知道这里应该使用什么配置吗?

提前谢谢你!

【问题讨论】:

    标签: symfony5 postmark symfony-mailer


    【解决方案1】:

    到目前为止,我刚刚开始使用 To、CC 和 BCC。

    我没有使用 Symfony5,但在我们的应用程序中实现了 SmyonfyMailer。

    我必须安装的软件包:

    composer require symfony/mailer
    composer require symfony/postmark-mailer
    composer require symfony/http-client
    

    如果您实例化 symfony 邮件程序类,您可以像这样传递传输对象(我使用 API,而不是 SMTP)。

    
    use Symfony\Component\Mailer\Mailer;
    use Symfony\Component\Mailer\Transport;
    
    $dsn = 'postmark+api://' . <postmark-api-key> . '@default';
    
    $transport = Transport::fromDsn($dsn);
    
    $mailer = new Mailer($transport);
    
    $email = (new Email())
                ->from('hello@example.com')
                ->to('you@example.com')
                //->cc('cc@example.com')
                //->bcc('bcc@example.com')
                //->replyTo('fabien@example.com')
                //->priority(Email::PRIORITY_HIGH)
                ->subject('Time for Symfony Mailer!')
                ->text('Sending emails is fun again!')
                ->html('<p>See Twig integration for better HTML integration!</p>');
    
    $mailer->send($email);
    
    

    【讨论】:

      猜你喜欢
      • 2019-11-30
      • 2010-12-03
      • 2021-10-02
      • 2016-08-02
      • 2015-08-11
      • 1970-01-01
      • 1970-01-01
      • 2022-07-11
      • 1970-01-01
      相关资源
      最近更新 更多