How to setup with ddev (local) environment (emails are not sent / error)

Created on 7 May 2023, over 1 year ago
Updated 7 December 2023, 12 months ago

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.

💬 Support request
Status

Closed: works as designed

Version

1.2

Component

Documentation

Created by

🇮🇹Italy kopeboy Milan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kopeboy
  • 🇦🇹Austria mvonfrie

    I 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 sendmail transport is set as default?

  • Status changed to Closed: works as designed about 1 year ago
  • 🇩🇪Germany Grevil

    DDEV 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:

    $settings['mailer_sendmail_commands'] = [
      ini_get('sendmail_path') . ' -t',
    ];
    

    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!

  • 🇧🇪Belgium flyke

    I 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:

    // 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';

    - 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:

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

    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:

    $settings['mailer_sendmail_commands'] = [
      ini_get('sendmail_path') . ' -t',
    ];

    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:

    // Add new transport command for sendmail.
    $settings['mailer_sendmail_commands'] = [
      ini_get('sendmail_path') . ' -t',
    ];
    // Use the new transport command.
    $config['symfony_mailer.mailer_transport.sendmail']['configuration']['query']['command'] = ini_get('sendmail_path') . ' -t';

    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:

    // Use Sendmail and use specific sendmail command for the Combell hosting.
    $config['symfony_mailer.settings']['default_transport'] = 'sendmail';
    // Add new transport command for sendmail.
    $settings['mailer_sendmail_commands'] = [
      '/usr/sbin/sendmail -t -fmyhostinguser@mydomain.be -t',
    ];
    // Use the new transport command.
    $config['symfony_mailer.mailer_transport.sendmail']['configuration']['query']['command'] = '/usr/sbin/sendmail -t -fmyhostinguser@mydomain.be -t';
  • 🇪🇪Estonia hkirsman

    I 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.

  • 🇩🇰Denmark ressa Copenhagen

    I use DDEV with Drupal Symfony Mailer enabled and Postmark for sending, and emails are intercepted with the default settings. My challenge is 📌 How to bypass Mailpit in DDEV? Active :)

Production build 0.71.5 2024