-1

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 "example@gmail.com" and password is "0000".

In .env.local I specified

MAILER_USER='example@gmail.com'
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='example%40gmail.com'

which then results in the error

Email "example%40gmail.com" 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://example@gmail.com:0000@default

So this seems to be a syntax problem which I can't figure out from the docs. Any hints?

Will B.
  • 17,883
  • 4
  • 67
  • 69
user3440145
  • 793
  • 10
  • 34

2 Answers2

1

You should remove the single quotes and you need to wrap the env variables used in other env variables with ${} sic

MAILER_USER=example@gmail.com
MAILER_PASSWORD=0000

MAILER_DSN=gmail://${MAILER_USER}:${MAILER_PASSWORD}@default

Result:

$_SERVER['MAILER_DSN'] = "gmail://example@gmail.com:0000@default"
Will B.
  • 17,883
  • 4
  • 67
  • 69
0

.env :

MAILER_DSN=smtp://username:password@smtp.gmail.com

You have to enable access to applications in google parameters (security).

Dharman
  • 30,962
  • 25
  • 85
  • 135
empty
  • 11
  • 2
  • You are talking about the less secure apps setting to turn on right? I did that allready. Changing to the syntax you provided doesn't change anything. Same error... – user3440145 Oct 22 '21 at 13:23