如何在Symfony 4的.env文件中配置MAILER_URL,用swift_Mailer通过sendmail发送电子邮件?

问题描述 投票:0回答:3

我正在使用Swift_Mailer发送电子邮件的Symfony 4应用程序。由于在我的情况下不可能使用SMTP(不要问为什么......)我必须使用像sendmail这样的东西。

默认情况下,Swift Mailer的配置是在一个名为.env的选项中以URL表示法在Symfony的MAILER_URL文件中完成的。默认值为“null://localhost”,根本不发送邮件。

所有我能找到的价值都是Gmail或SMTP的一个例子,如Symfony docs以及Composer生成的示例.env中所记录的那样。

.env的默认内容:

# …

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###

# …

我不知道什么,因此我的问题是:

我需要做些什么才能让sendmail使用它?

我已经尝试过类似的东西:

MAILER_URL=sendmail://localhost

MAILER_URL=sendmail://my-domain.com

但到目前为止没有成功。

使用console命令时

bin/console swiftmailer:email:send

我甚至得到了“[OK] 1封电子邮件已成功发送。”结果,但实际上没有发送电子邮件。 (...顺便说一下,没有假脱机.bin/console swiftmailer:spool:send返回“发送的0封电子邮件”。)邮件传递似乎是中断的,因为邮件不会在我的邮件帐户上进行,而且我的垃圾邮件也是空的。

另一方面,直接调用sendmail命令确实有效。 (虽然我的测试邮件到达了我的垃圾邮件,但仍然是:邮件被发送了。)

同样,我如何在Symfony 4中的MAILER_URL中为Swift_Mailer配置.env以使用sendmail

有可能吗?

php email sendmail swiftmailer symfony4
3个回答
3
投票

好吧,符号已经是正确的。所以这个有效使用sendmail

MAILER_URL=sendmail://my-domain.com

我的实际问题是邮件的假脱机是活跃的。我从spool配置中注释掉了swiftmailer.yaml条目。

顺便看看Symfony Profiler对我有很大帮助。

...我的邮件仍未到达,但我确信这与MAILER_URL无关。所以,我的问题得到了回答。


1
投票

在我的yaml修复问题中评论假脱机


0
投票

我不确定我的问题是否正确但在我的情况下我使用的是Gmail帐户,这是我的.env文件的第23行

MAILER_URL=gmail://[email protected]:myemailpassword@localhost

你已经安装了composer require symfony/swiftmailer-bundle的SwiftMailer吗? (对不起我的英语不好)


0
投票

试试这个配置:

swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
transport: 'sendmail'
command: '/usr/sbin/sendmail -oi -t'

得到这位朋友:

/没有_是否4_project/config/packages/Swift买了R.压马路

我正在使用Symfony 4.3.1和SwiftMailer 6.2.0。您可以在SwiftMailer包文档中阅读:

/**
 * Start the standalone SMTP session if running in -bs mode.
 */

然后:

/**
 * Set the command to invoke.
 *
 * If using -t mode you are strongly advised to include -oi or -i in the flags.
 * For example: /usr/sbin/sendmail -oi -t
 * Swift will append a -f<sender> flag if one is not present.
 *
 * The recommended mode is "-bs" since it is interactive and failure notifications
 * are hence possible.
 *
 * @param string $command
 *
 * @return $this
 */

使用这些注释的文件路径:

供应商/ swiftmailer / swiftmailer / lib中/班/雨燕/运输/ SendmailTransport.php

在更改为'/ usr / sbin / sendmail -oi -t'之前,我收到了来自SwiftMailer的错误:

app.ERROR:刷新电子邮件队列时发生异常:预期响应代码220但得到空响应[] []

更改sendmail参数后,我正在成功发送邮件。

© www.soinside.com 2019 - 2024. All rights reserved.