如何在SMTP传输中的Symfony Mailer组件的凭据中处理特殊字符?

上下文

在Symfony 4.3中,引入了新的电子邮件程序。

查看此处:

对于SMTP传输,已确定ENV变量中的Dsn具有以下格式:

MAILER_Dsn=smtp://user:pass@smtp.example.com

问题

编写Dsn时如何处理用户名和密码中的特殊字符?

让我们假设凭据是:

username: alice@example.com
password: the:password:is:difficult

像这样的设置很可能会失败:

MAILER_Dsn=smtp://alice@example.com:the:password:is:difficult@smtp.example.com

我应该如何编码/转义内容?正确的Dsn是什么?

king1302218 回答:如何在SMTP传输中的Symfony Mailer组件的凭据中处理特殊字符?

您可以对值进行urlencode。

邮件程序组件(Tests/Transport/DsnTest.php)中进行了一项测试,表明它应该与编码值一起使用。

enter image description here

因此您可以使用在线编码器来转换值(例如https://www.urlencoder.org/

您的字符串:

MAILER_DSN=smtp://alice@example.com:the:password:is:difficult@smtp.example.com

成为:

MAILER_DSN=smtp://alice%40example.com:the%3Apassword%3Ais%3Adifficult@smtp.example.com
,

接受的答案是正确的。但是无需编码或转义用户名或密码。我成功尝试了包含@字符的用户名以及包含:=以及|,的密码。

这是有效的配置:

MAILER_DSN=smtp://alice@example.com:the:pa=|,ssword@smtp.example.com:587
本文链接:https://www.f2er.com/2962291.html

大家都在问