Lost Password Email not sending

Silverstripe Version: 4.7

Question:
Hi everybody! We have noticed that our Password Reset Form does not send the reset mail to our users. We do have another form on our site that does work for the specific DNS / SMTP Server.
I have followed this SS Doc https://docs.silverstripe.org/en/4/developer_guides/email/ for the setup, but it still does not send any mails when using the Lost Password? form / feature.
Has anybody experienced this before?

```
---
Name: myemailconfig
After:
  - '#emailconfig'
---
SilverStripe\Core\Injector\Injector:
  Swift_Transport:
    class: Swift_SmtpTransport
    properties:
      Host: smtp.host.com
      Port: <port>
      Encryption: tls
    calls:
      Username: [ setUsername, ['`APP_SMTP_USERNAME`'] ]
      Password: [ setPassword, ['`APP_SMTP_PASSWORD`'] ]
      AuthMode: [ setAuthMode, ['login'] ]
```

and in my .env
MAILER_DSN="…"
APP_SMTP_USERNAME="…"
APP_SMTP_PASSWORD="…"

So, the first question is: Are you sure they aren’t being sent, or are they just not being received?
Do you have any visibility in the SMTP service of the messages coming in? Are there any mailing logs anywhere you can check?

If you know the configuration actually works, then there may be a few other things to check:

  • Do you have the sender domains set up in the site configurations?
  • Do you have the default sender address set up?
  • Do you have all the relevent SPF / DKIM records in place for the domain you’re sending from?
  • Is the server that’s having problems behind any kind of firewall / are there restrictions on the ports it is allowed to use?
  • Is the password reset the only thing that isn’t working? Are there any other functions on the site which send emails?

Hi Tim! Thank you so much for your full on response, it already gave a lot of insight. Weirdly enough, our separate contact form does work - we have setup MAILER_DSN=“smtp://user:pw@wever:port” in our .env, but it apparently does not apply to the system mails.
I have added

SilverStripe\Core\Injector\Injector:
SilverStripe\Control\Email\Email:
    properties:
      default_from: 'info@example.com'

to the email.yml
&

MySiteEmailConfiguration:
  sender_domains:
    - example.com

to the mysite.yml
both did not resolve the issue.
At this point in time, we do not have access to further logging, since we are freelancing on this project for a customer who is hosting with another company.
Thanks again and best regards!

You may need to set the “admin email” which is the email address these emails will be sent from:

# app/_config/app.yml
SilverStripe\Control\Email\Email:
  admin_email: support@example.com

Hi there! Thanks for your comment - we did indeed not have that setup! Sadly, adding it did not resolve our issue. Weirdly enough, our separate contact form does work - we have setup MAILER_DSN=“smtp://user:pw@wever:port” in our .env, but it apparently does not apply to the system mails.

MAILER_DSN is for Silverstripe CMS 5 - for Silverstripe CMS 4 you need to use the swiftmailer settings as per https://docs.silverstripe.org/en/4/developer_guides/email/ - which you are using according to your original post.

May be worth dropping a breakpoint in and stepping through with a debugger to see if swiftmailer is even trying to send an email, and if so what the details of the email are.

I found the reason / solution! Apparently it is a common issue in v4.4/4.7 - email templating broken · Issue #8628 · silverstripe/silverstripe-framework · GitHub
I had to configure the Email:: in the Member.php and the LostPasswordHandler.php to something like

        $to = $member->Email;
        $from = 'info@example.com';
        $subject = "Subject";
        $resetLink = Security::getPasswordResetLink($member, $token);

        $messageBody = "Content";
        $email = Email::create($from, $to, $subject, $messageBody)->setHTMLTemplate('EmailBody');
        return $email->send();