Problem/Motivation
I can't send emails from my local ddev environment.
Steps to reproduce
Start a D10 project with ddev, enable this module and test email: not sent
Alternative I tried: comment out these (ddev default) settings from settings.ddev.php :
// Override drupal/symfony_mailer default config to use Mailhog
$config['symfony_mailer.mailer_transport.sendmail']['plugin'] = 'smtp';
$config['symfony_mailer.mailer_transport.sendmail']['configuration']['user']='';
$config['symfony_mailer.mailer_transport.sendmail']['configuration']['pass']='';
$config['symfony_mailer.mailer_transport.sendmail']['configuration']['host']='localhost';
$config['symfony_mailer.mailer_transport.sendmail']['configuration']['port']='1025';
Try sending test email and receive error:
Error sending email: Connection to "process /usr/sbin/sendmail -bs" has been closed unexpectedly.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | sm-transport-sendmail.png | 18.61 KB | flyke |
Comments
Comment #2
mvonfrie commentedI have the exact same configuration (D10.0.9, DDEV 1.21.5) and for me this works out of the box. Can you check if the
sendmailtransport is set as default?Comment #3
grevil commentedDDEV uses Mailpit (formerly Mailhog) internally, which doesn't support the sendmail "-bs" flag. To fix this issue, you need to add the following code to your settings.local.php:
and then go to the "sendmail" transport entity (/admin/config/system/mailer/transport/sendmail) and select your newly added sendmail command. (This is also documented here.
I hope, that fixes your issue!
Comment #4
flyke commentedI learned a lot of things the hard way unfortunatly, but here are some things that I learned for future reference:
- symfony_mailer does not work well with mail_safety module. So if you are using mail_safety, then that might be the reason no mails end up in mailhog. Use symfony_mailer_log module instead for logging emails.
- You don't need a Native or an SMTP transport. Sending emails local via ddev to mailhog and actually sending out emails on production server both work with sendmail. If that is your use case, and you dont need to use Native or SMTP on your production environment, you may safely delete the Native and SMTP transports if you have them.
- The out of the box settings that ddev generates in settings.ddev.php are good, no need to change or override them:
- If you have trouble sending emails because of the default -bs parameter (usually not on your ddev environment but it can happen on your hosting), and you have an error like this:
then you do indeed need to make adjustments. Here is where some info you can find in various issues here is wrong.
What happens when you add this to your settings file:
is that it just adds a new Command option that you can see when you edit the Sendmail transport at /admin/config/system/mailer/transport/sendmail.
You also need to actually edit the sendmail transport, select the new command and save it.
You can also do this via your settings file by adding this extra line:
I myself do this via settings file(s) because I have a local settings file for my ddev environment and another environment specific settings file, like one for production.
If you use
ini_get('sendmail_path') . ' -t'locally in your settings and use that, and if you then export your site config and deploy it, you end up actually deploying your local ddev sendmail path as setting (like'/usr/local/bin/mailhog sendmail test@example.org --smtp-addr 127.0.0.1:1025 -t') which may cause you problems on the environment you deployed to. For me it worked better to use actual sendmail path in my production settings file instead of ini_get('sendmail_path'), like this:Comment #5
hkirsman commentedI removed all of the $config['symfony_mailer. and everything still works. E-mails are being sent. As far as I know we don't have any contrib e-mail modules in our site.
Comment #6
ressaI use DDEV with Drupal Symfony Mailer enabled and Postmark for sending, and emails are intercepted with the default settings. My challenge is #3406739: How to bypass Mailpit in DDEV? :)
Comment #7
someshver commentedSimplified setup for Symfony Mailer in DDEV using Mailpit
/admin/config/system/mailer/transportlocalhost1025/admin/config/system/mailer/test, enter any recipient email, and click Send.This configuration uses Mailpit for local email capture in DDEV, making it easy to verify outgoing messages during development.