Symfony 4 SwiftMailer Gmail : Email not sent
Asked Answered
B

5

7

I'm currently working on a Symfony 4 application and I need to send emails throught Swift Mailer. When I send an email, I receive the email spooled but I don't get it in my Gmail Mailbox. I allowed unsecure apps in my gmail configuration.

This is my mailer URL from .env file : MAILER_URL=gmail://ep****@gmail.com:PASSWORD@localhost

This is my swiftmailer.yaml:

    #config/packages/swiftmailer.yaml
    swiftmailer:
        url: '%env(MAILER_URL)%'
        spool: { type: 'memory' }

This is my controller function:

src/Controller/AccountController.php

After completing a form

This is the documentation I've followed : http://symfony.com/doc/current/email.html

I've checked these questions but they don't give me the answer : How to send emails with Symfony 4 Swiftmailer from a local machine running on Windows 10? , mailer symfony 4 not working

Please, I need help. I've looked for the solution all day long. I get no errors but I don't receive the mail. Thanks in advance. Any link can help me.

Bandung answered 21/2, 2018 at 21:9 Comment(6)
please refrain from posting a snapshot of the code instead of the code itselfPedaias
Did you set up a CRON job to process the spool? Did you try omitting the spool config setting? Is spooling a requirement?Rutland
I didn't set it. I tried omitting the pool but there's no change.Bandung
I have the same issue. Did you solve it? @SalveSafariSudden
Yes, I solved it :) Please, read belowBandung
This is my solution. It works perfect on symfony 4.x https://mcmap.net/q/1483579/-mailer-symfony-4-not-workingAdvantage
B
14

Problem solved!! Put this configuration instead of using the URL env variable

swiftmailer:
    transport:        gmail
    username:         ****@gmail.com
    password:         *******
    host:             localhost
    port:             465
    encryption:       ssl
    auth-mode:        login
    spool: { type: 'memory' }
    stream_options:
        ssl:
            allow_self_signed: true
            verify_peer: false
            verify_peer_name: false
Bandung answered 6/3, 2018 at 18:28 Comment(3)
Merci! That made the trick. Any idea why the .env file not working ?Decaliter
I noticed going from Symfony 3 to Symfony 4 local SMTP is not enabled anymore. To use local SMTP in your .env set MAILER_URL=smtp://localhost:25?encryption=&auth_mode=Celestine
Sage answer. Saved hours of frustration. Thank you @Selve!Loeb
P
3

Late to the party, but the URL format requires full settings. I don't think SwiftMailer parses the URL to detect a specific transport (like gmail) to configure the reset by itself.

The following format worked for me:

MAILER_URL=smtp://smtp.gmail.com:587?encryption=tls&username=USERNAME&password=PASSWORD
Purdah answered 30/1, 2019 at 10:44 Comment(0)
S
2

In my experience, you will need enable "Allow unsafe logins" in a Google Suite or Gmail account since they prevent access via SMTP.

Sri answered 5/2, 2019 at 2:43 Comment(0)
N
1

Comment out the spooler line

swiftmailer:
url: '%env(MAILER_URL)%'
#spool: { type: 'memory' }
Nonprofessional answered 14/5, 2019 at 16:4 Comment(1)
Thank you so much you helped me a lot :)Humanitarianism
H
0

MAILER_URL must be url encoded. Check out the documentation at: https://symfony.com/doc/current/email.html#configuration

If your password had some special characters in it, that needed to be url encoded, it won't work.

Hope it helps.

Halogen answered 1/9, 2018 at 0:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.