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.
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]
So I installed true/punycode package via:
No IDN encoder found (install the intl extension or the true/punycode package
composer req true/punycode
and now emails are sending fine also with spool memory.
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.
来源:https://stackoverflow.com/questions/49800778/symfony-4-swift-mailer-doesnt-send-mails