FosUserBundle don't send email to resset password - symfony

I have a simple form to login and reminder password, I overwrite the FOSUser template and everything works fine, but when I want to email the password reminder I do not get it to the mail.
This looks like a swiftmailer and fos configuration in config.yml:
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: AirblogBundle\Entity\User
from_email:
address: "admin#admin.com"
sender_name: "Admin"
resetting:
email:
from_email:
address: noreply#yoursite.com
sender_name: No Reply
token_ttl: 0
After sending the email from the resetting/request path, I get the following information:
An email has been sent to ...#wp.pl. It contains a link you must click to reset your password.
Which seems correct because the address entered in the form has the same ending, but my mailbox does not receive any message.
ps: One more question, how to simply overwrite the Twig template, so the login and reminder of the hymn was on one page? Do you need to overwrite the controller?

Did you configure the needed parameters of SwiftMailerBundle well ?
First of all I suggest you to use Symfony's command to check your swift mailer configuration.
Specify the good arguments to send you a debug mail with reading the help command
php app/console swiftmailer:email:send --help
You should receive a mail on the email address you wrote in command.
After this step you can assume that your mail configuration is good
Reset your forget password request
One important (in the version installed on my project, composer requirement ~2.0) thing to know that is FOSUserBundle don't resend mail if you didn't click on the previous reset link sended BUT he display to you the message that he sended the mail.
If you want to "reset" your password request for a specific user
UPDATE user SET confirmation_token = NULL, password_requested_at = NULL WHERE username = "yourdebugusername"
Extending FOSUserBundle Twig templates
You should read this documentation
Basically you can override all the FOSUserTemplate under vendor/friendsofsymfony/user-bundle/Resources/views
I hope it's help !

For overriding FOSUser twig template looks the Symfony Doc

Related

FosUserBundle Confirm Email after registration

I want to do email confirmation after each registration of new user in my website, so when the registration is done the system must redirect him to anther page that tells that he should confirm his email address, and only give access only to users they had an activated mail address.
My config file is:
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\User
registration:
confirmation:
from_email: # Use this node only if you don't want the global email address for the confirmation email
address: test#example.com
sender_name: Example sender
enabled: true # change to true for required email confirmation
template: '#FOSUser/Registration/email.txt.twig'
This is the error I am getting:
Type error: Argument 1 passed to FOS\UserBundle\EventListener\EmailConfirmationListener::onRegistrationSuccess() must be an instance of FOS\UserBundle\Event\FormEvent, instance of FOS\UserBundle\Event\GetResponseUserEvent given
EmailConfirmationListener onRegistrationSuccess must be an instance of FormEvent
What you are trying to achieve is something that happens by default. It seems like you changed an eventlistener or made a new one that does not work. Also, in your config file 'template:' does not seem to be in the right place because it does not line up with 'enabled' and 'from_email'.

Symfony 3 : Swiftmailer won't send email from website while working with the swiftmailer:email:send command

I face a problem I don't understand.
I use SwiftMailer to send emails (ex : registration confirmation) from a website using the Mailjet SMTP. Mails are not sent.
The Symfony profiler says that 1 mail is spooled when I create a user account, but it is never sent.
php bin/console swiftmailer:spool:send returns 0 emails sent. I tried memory and file spools.
When using the php bin/console swiftmailer:email :send, mails are correctly sent (mails have the mailjet headers and they are in the mailjet sent mails interface).
When I'm trying the OVH SMTP, mails are correcly sent both from the application and cli command, so the problem seems to be a SwiftMailer misconfiguration.
Here is my setup :
app/config/config.yml
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host_prod%"
port: "%mailer_port_prod%"
encryption:"%mailer_encryption_prod%"
username: "%mailer_user_prod%"
password: "%mailer_password_prod%"
spool: { type: memory }
app/config/parameters.yml
mailer_transport: smtp
mailer_host_prod: in-v3.mailjet.com
mailer_port_prod: 587
mailer_encryption_prod: tls
mailer_user_prod: api_key
mailer_password_prod: api_secret
mailer_host_ovh: ssl0.ovh.net
mailer_port_ovh: 465
mailer_encryption_ovh: ssl
mailer_user_ovh: email
mailer_password_ovh: password
It works for me. I had the same issue, but I had an exit after sending the email and in this case, the spool doesn't send the email, because the kernel does not end properly. If you remove spool: { type: memory }, then it will send the email.
To send the email properly with spool, then you need to end the kernel properly.
Did your request finish without any errors when creating the message ?
On https://symfony.com/doc/current/email/spool.html : "This means the email only gets sent if the whole request got executed without any unhandled exception or any errors."
Finally, it was the sender's email who was wrong. I forgot to update it after going prod.
At this moment, Mailjet successfuly receive the email but put it in queue and don't send it. On Symfony side, it is a success.

FOSUser mail is translated but confirmation_url isn't

I found an easy way of adding a locale to my Symfony routes, as described here: Locale switch in login of FOSUserBundle
Some relevant settings in my project:
config
framework:
translator: { fallback: "%locale%" }
default_locale: nl
services
fosmailer: #fos_user.mailer.twig_swift
routing
fos_user_register:
resource: "#FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /{_locale}/registreren
I'm trying to get FOSUser to send a confirmation mail in the newly created users' browserlanguage.
For this I'm saving the locate found by javascript in my database.
Then, I'm setting my request to that locale and send the confirmation mail manually like this:
$request->setLocale($locale); //($locale = 'en_US')
$mailer = $this->get('fosmailer');
$mailer->sendConfirmationEmailMessage($user);
My email template contains a bunch of {{ 'foobar' | trans}} tags, which work perfectly fine. But I'm also using the {{confirmationUrl}} which is generated by FOSUser.
In an English mail this confirmation url will still show up as:
/nl/registreren/confirm/1234..
Any ideas why my mail is localized but my url isn't?
The URL address is not translated, because localization of URL addresses is not part of standard Symfony2 installation.
In order to localize URL addresses you need to use some bundle which solves this issue, for example BeSimpleI18nRoutingBundle or you can create your own solution.

FOSUserBundle sending bad confirmation links

1 or 2% of users registering seem to get no confirmation email or they get a bad token appended to the confirmation link in the email. I can't determine why or where this wrong token comes from. It doesn't look like a truncated version of the correct one. It's totally different. Clicking it yields a 404 response.
I am not overriding the RegistrationController.
Could it be the mailer settings?
swiftmailer:
~
spool: { type: memory }
The only other changes I've made were in validation of a few custom fields.
registration:
form:
type: acme_user_registration
validation_groups: [MyRegistration]
confirmation:
enabled: true
Any ideas what's going on?
Thanks.
I found a problem while viewing a confirmation email in outlook.com. I turns out that outlook.com is 'previewing' the link to show some expanded metadata in the email message. This has the side effect of enabling the user and deleting the token. Once the user actually clicks the link, they get a token not found error, but their account is enabled.

How to define an additional mailer service to use the spool and send instant emails in Symfony2

In my Symfony2 web app I'm supposed to send two kind of emails: instant and bulk. The instant emails should be send right away while the bulk emails should be send using the spool. With the default configuration of the Swiftmailer in Symfony2 it is impossible to do that because there is only one mailer service.
Similar questions has been asked here in SO ( How to spool emails (in a task) and send normal emails in the moment in the other controllers? ) with no luck, but according to this github thread ( https://github.com/symfony/SwiftmailerBundle/issues/6 ) it is possible to create a second mailer service that can be configured totally different than the default one. Someone there (stof) recommended as a possible solution to follow the configuration found in the SwiftmailerBundle ( https://github.com/symfony/SwiftmailerBundle/blob/master/Resources/config/swiftmailer.xml ) to create this new service, but I don't know how exactly do that.
Does anyone know how to create an additional mailer service that I can configured as a spool while having the default mailer service to send regular (instant) emails?
I found the solution here
This is how I implemented it:
First, I configured the default mailer service to work as a spool to send bulk emails.
(config.yml)
swiftmailer:
transport: %mailer_transport%
encryption: %mailer_encryption%
auth_mode: %mailer_auth_mode%
host: %mailer_host%
username: %mailer_user%
password: %mailer_password%
spool:
type: file
path: "%kernel.root_dir%/spool"
Then, inside one of my bundles (CommonBundle) I registered a new service called "instant_mailer" that maps to the Swiftmailer class.
(service.yml)
instant_mailer:
class: %swiftmailer.class%
arguments: ["#?swiftmailer.transport.real"]
Finally, in my controller, whenever I want to send an email usning the spool I just do:
$mailer = $this->get('mailer');
And to send an instant email:
$mailer = $this->get('instant_mailer');

Resources