In Symfony 4.3 a new emailer was introduced.
See here:
For the SMTP transport it is established that the DSN in the ENV var has this format:
MAILER_DSN=smtp://user:[email protected]
How do I handle special characters in the user and password when writing the DSN?
Let's suppose that the credentials are:
username: [email protected]
password: the:password:is:difficult
Setting like this most likely will fail:
MAILER_DSN=smtp://[email protected]:the:password:is:[email protected]
How should I encode/escape things? What would be a correct DSN for it?
You can urlencode the values.
There's a test in the Mailer component (Tests/Transport/DsnTest.php) indicating that it should work with encoded values.
So you can use an online encoder to convert your values (e.g.https://www.urlencoder.org/)
Your string:
MAILER_DSN=smtp://[email protected]:the:password:is:[email protected]
Become:
MAILER_DSN=smtp://alice%40example.com:the%3Apassword%3Ais%[email protected]
The accepted answer is correct. But there is no need to encode or escape neither the username nor the password. I successfully tried a username containing a @
character as well as a password containing :
and =
and |
and ,
.
So this is a valid config:
MAILER_DSN=smtp://[email protected]:the:pa=|,[email protected]:587
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With