Symfony 4 Swift Mailer doesn't send mails
Asked Answered
C

2

3

I´m working in a localhost server with Symfony 4 and FOSUserBundle. I can't manage to receive the email confirmation when a new user is registered.

I have tried the following post but it´s not working in my case: Symfony 4 SwiftMailer Gmail : Email not sent

I have tried to configure SwiftMailer to send using gmail smtp server and mailtrap smtp server without success. Also I have checked dev.log and no errors are found.

I´m not sure which is the right file to configure Swift Mailer (.env or packages/dev/swiftmailer.yaml). Right now the configuration is the following:

.env file:

MAILER_URL=gmail://***@gmail.com:***@localhost

swiftmailer.yaml:

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 

Any ideas? It´s not mandatory to use gmail as the smtp server.

Thanks beforehand.

SOLUTION:

The problem was in the /config/test/fos_user.yaml file:

I changed:

service:
  mailer: 'fos_user.mailer.noop'

To:

service:
  mailer: 'fos_user.mailer.default'

Documentation: http://symfony.com/doc/master/bundles/FOSUserBundle/emails.html

Also I have accepted less secure connections from the gmail account setting in order to work.

Convert answered 12/4, 2018 at 15:43 Comment(5)
Can you try to remove parameters port, host, auth-mode and retry a send plzHillier
Still not workingConvert
If you try to send a mail via the swiftmailer:email:send command, what is the output?Inspissate
I have edited the question to add the solution. Thanks for the comments and help ;)Convert
Glad you solved your issue. Please remove the solution from your question, put it in an answer and accept your answer, it might help others.Inspissate
B
4

I had the same problem with Symfony 4. My packages version swiftmailer/swiftmailer v6.1.0 symfony/swiftmailer-bundle v3.2.2 When I used configuration: swiftmailer: url: '%env(MAILER_URL)%' spool: { type: 'memory' }

The emails were not send and no exception occurred. Then I change the settings into:

swiftmailer: url: '%env(MAILER_URL)%' spool: type: 'file' path: '%kernel.cache_dir%/swiftmailer/spool'

And tried command:

php bin/console swiftmailer:spool:send --env=dev -vvv

And I saw the error:

[Swift_SwiftException]
No IDN encoder found (install the intl extension or the true/punycode package
So I installed true/punycode package via:

composer req true/punycode

and now emails are sending fine also with spool memory.

Butanone answered 4/7, 2018 at 12:9 Comment(0)
M
2

Default behaviour of Symfony mailer is to send the email messages immediately, but as you configured, it will "spool" the emails instead of sending them directly.

spool: { type: 'memory' }

Sending the messages from the spool is done separately, with a console command:

php bin/console swiftmailer:spool:send --env=dev

@see more docs here

UPDATE: As @nek said on the first comment, the the memory spool send the mail immediately (if none exception occured). The spool:send command is only required when using the file spool.

Motherwort answered 13/4, 2018 at 6:46 Comment(1)
The memory spool send the mail immediately (if none exception occured). The spool:send command is only required when using the file spool.Amphioxus

© 2022 - 2024 — McMap. All rights reserved.