Try to use Symfony mailer with Gmail
Asked Answered
W

5

5

Try to use Symfony mailer with Gmail on my Symfony 5.1 app.

mailer.yaml:

framework:
    mailer:
        dsn: '%env(MAILER_DSN)%'

.env:

MAILER_DSN=gmail+smtp://[email protected]:mypassword@localhost

But each time I send a mail, I got:

Connection could not be established with host "ssl://smtp.gmail.com:465": stream_socket_client():
SSL operation failed with code 1. OpenSSL Error messages:
error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed

Don't understand why... According to the https://symfony.com/doc/current/mailer.html it should work.

I activated low security app on my Gmail account.

Thanks for help

Wingfield answered 2/9, 2020 at 16:47 Comment(0)
S
7

To use Gmail, you need the package symfony/google-mailer (composer require symfony/google-mailer)

And this configuration in your .env file:

###> symfony/google-mailer ###
# Gmail SHOULD NOT be used on production, use it in development only.
MAILER_DSN=gmail://YourEmailAddress:YourPassword@default?verify_peer=0
###< symfony/google-mailer ###

An example:

MAILER_DSN=gmail://[email protected]:admin123@default?verify_peer=0

Warning:

Although it’s not recommended to disable this verification for security reasons, it can be useful while developing the application or when using a self-signed certificate

Santo answered 3/9, 2020 at 7:53 Comment(4)
I forgot to precise but of course I installed symfony/google-mailer, and if I put MAILER_DSN=gmail://[email protected]:mypassword@default I got nearly the same error: Connection could not be established with host "ssl://smtp.gmail.com:465": stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failedWingfield
Try with ?verify_peer=0 at the end of your DSN. See docSanto
Indeed, it's working without TLS Peer Verification, with: MAILER_DSN=smtp://[email protected]:[email protected]?verify_peer=0. Don't know if it a good idea to disabled TLS Peer Verification but, it works... Thanks LiscareWingfield
Doesn't work at all. Symfony has so low quality of the email documentation.Nottage
C
4

I know you've said you've done it, but I usually get this error because I need to allow "less secure apps" on my Gmail account.

  1. Connect to Gmail
  2. Go to https://www.google.com/settings/security/lesssecureapps and click Authorize
  3. Go to https://accounts.google.com/DisplayUnlockCaptcha and click Continue
  4. Retry sending an email from your website, and if it still doesn't work repeat points 2 & 3. Sometimes I have to try a few times...
Coston answered 18/9, 2020 at 3:10 Comment(0)
H
1

That can come from an async property that is defined by config/packages/messenger.yaml see https://github.com/symfony/symfony/issues/45811

Homerhomere answered 22/4, 2022 at 7:2 Comment(0)
M
0

You need to make sure you are using an SSL certificate when sending emails through Gmail.

See:

https://symfony.com/doc/3.0//email/gmail.html

Mastery answered 2/9, 2020 at 17:40 Comment(1)
But I'm using Symfony 5.1 Mailer, not Swiftmailer. The config is not the sameWingfield
A
0

with mailer you can do this :

MAILER_DSN=smtp://USER:[email protected]:465?encryption=ssl&auth_mode=login

Regards

Aparejo answered 25/7, 2024 at 8:29 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.