2

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

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

邮戳+smtp:// ID @default

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

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

先感谢您!

4

1 回答 1

0

到目前为止,我刚刚开始使用 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);

于 2021-11-17T10:52:25.037 回答