Silverstripe throwing sendmail error on ForgotPassword form and member password change

138 views Asked by At

I'm having an issue where trying to use the ForgotPassword form, or trying to change a users existing password in admin/Security throws the following error:

Connection to "process /usr/sbin/sendmail -bs" has been closed unexpectedly.

This happens in a production site where SS_ENVIRONMENT_TYPE="live" but not when I change it to "dev"

I have the following config for email using Mailgun:

---
Name: myemailconfig
After:
  - '#emailconfig'
Only:
  environment: 'live'
---
SilverStripe\Core\Injector\Injector:
  Swift_Transport:
    class: Swift_SmtpTransport
    properties:
      Host: smtp.mailgun.org
      Port: 587
      Encryption: tls
    calls:
      Username: [ setUsername, ['`MAILGUN_SMTP_USERNAME`'] ]
      Password: [ setPassword, ['`MAILGUN_SMTP_PASSWORD`'] ]
      AuthMode: [ setAuthMode, ['login'] ]

Any ideas why this would be happpening or what the fix could be??

2

There are 2 answers

1
Işıksoft Yazılım On

The error you're seeing, "Connection to process /usr/sbin/sendmail -bs has been closed unexpectedly," typically indicates an issue with sending mail from your server using the Sendmail program. Since you're using Mailgun for email delivery, you shouldn't need to rely on Sendmail at all.

Your problem might be related to the way SilverStripe is trying to send emails in the live environment, possibly falling back to a default Sendmail configuration because of some reason. Here are steps to help diagnose and fix the issue:

Check Configuration Values: Ensure that the environmental variables MAILGUN_SMTP_USERNAME and MAILGUN_SMTP_PASSWORD are correctly set and accessible in the live environment.

Ensure SwiftMailer Configuration: Make sure you're using SwiftMailer as the mailer. Add this configuration to your app/_config/email.yml:

---
Name: myemailconfig
After:
  - '#emailconfig'
Only:
  environment: 'live'
---
SilverStripe\Core\Email\Email:
  send_all_emails_to: '' # Make sure this is empty to prevent redirecting all emails to a single address
  send_all_emails_from: '[email protected]' # Replace with your domain or the desired sender address
  mailer: 'swift'

0
galilee On

Ok, so it turns out Silverstripe has moved to using symfony/mailer from SS5, which I hadn't picked up on. So the fix was pretty easy - changing around the config to use MAILER_DSN, and adding the mailgun bridge to the project composer require symfony/mailgun-mailer