In a Symfony 5.3 project I am using the Mailer (..\Symfony\Component\Mailer\MailerInterface) to send mails. For devolopment I required "symfony/google-mailer" with composer and set it up in .env.local. Say username is "[email protected]" and password is "0000".
In .env.local I specified
MAILER_USER='[email protected]'
MAILER_PASSWORD='0000'
MAILER_DSN=gmail://MAILER_USER:MAILER_PASSWORD@default
which results in error
Failed to authenticate on SMTP server with username "MAILER_USER" using the following authenticators: "LOGIN", "PLAIN", "XOAUTH2". Authenticator "LOGIN" returned "Symfony\Component\Mailer\Exception\TransportException: Expected response code "235" but got code "535", with message "535-5.7.8 Username and Password not accepted.
As stated in the docs I changed the one special character in user name ("@") to it's URL-encoded form like
MAILER_USER='[email protected]'
which then results in the error
Email "[email protected]" does not comply with addr-spec of RFC 2822.
(Obviously the URL-encoding didn't work like expected (because it wasn't reversed?)) I tried to load the env vars in paramaters in services.yaml and use the parameters instead - but that lead to the first error too.
If I write the auth infos into the MAILER_DSN env var directly it just works fine without problems, like
MAILER_DSN=gmail://[email protected]:0000@default
So this seems to be a syntax problem which I can't figure out from the docs. Any hints?
CodePudding user response:
.env :
MAILER_DSN=smtp://username:[email protected]
You have to enable access to applications in google parameters (security).
CodePudding user response:
You should remove the single quotes and you need to wrap the env variables used in other env variables with ${}
sic
[email protected]
MAILER_PASSWORD=0000
MAILER_DSN=gmail://${MAILER_USER}:${MAILER_PASSWORD}@default
Result:
$_SERVER['MAILER_DSN'] = "gmail://[email protected]:0000@default"