Problem/Motivation

Site had Swiftmailer so trying this module and need full attachment support. For local dev I have Docker/DDEV with Mailpit. Swiftmailer was using a sendmail transport and was working. Now with SML, If I use sendmail with your default options (/usr/sbin/sendmail -bs), I get this error:

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

Changing "-bs" to "-t" does not give any error but also doesn't send anything either. And if there are no options besides bs or t, it throws an error telling that.

Then I discovered that using Native transport, everything worked perfectly! I did a test order with attachments, and everything came though to Mailpit. But now on the stage server, which has Mailhog, if I stay with the Native as the default transport, I get this error:

InvalidArgumentException: Unsupported sendmail command flags "/opt/mailhog/mhsendmail"; must be one of "-bs" or "-t" but can include additional flags. in Symfony\Component\Mailer\Transport\SendmailTransport->__construct() (line 58 of /var/www/tetramer/code/2023-10-15-19644-39046/vendor/symfony/mailer/Transport/SendmailTransport.php).

I'm assuming that Native means whatever the OS is doing? But if I use the sendmail or msendmail option for that transport, I'm back to the same issues I had locally for sendmail.

Can you help me understand what are all the moving parts here? Since I got it working locally, I just need to find the right settings for stage, and then eventually for prod. Thanks!

Comments

JCL324 created an issue. See original summary.

yujiman85’s picture

Any update on this? I'm having a very similar issue.

jaypan’s picture

I just hit this issue in DDev. To configure this module to work with Mailpit in DDev, you can do the following:

  1. Navigate to Admin -> Configuration -> System -> Drupal Symfony Mailer Lite (Transport tab)
  2. Under Transport Type, select SMTP and click Add Transport
  3. Use the following settings:
    Label
    Mailpit
    Host name
    0.0.0.0
    Port
    1025

    Click save

  4. In the operations drop-down, click the arrow for the new Mailpit transport type, and select 'Set as default'
  5. Test and confirm
mxr576’s picture

Status: Active » Closed (works as designed)

This issue and especially this part just confirms to me that there is no one-transport-rule-them-all configuration on your project when every environment is different (local, QA, production).

I'm assuming that Native means whatever the OS is doing? But if I use the sendmail or msendmail option for that transport, I'm back to the same issues I had locally for sendmail.

Therefore I'd suggest registering multiple transports (#3 is also a valid transport config) and switching the default transport in symfony_mailer_lite.settings config in an environment-specific settings.php via config overrides. (I hope those are supported in your setup too.)

This is what we did with Swiftmailer in the past and would do with this module and Drupal Symfony Mailer too.

flyke’s picture

Add this in your sites/default/settings.ddev.php if you are using SMTP transport:

// Override drupal/symfony_mailer_lite default config to use Mailpit
$config['symfony_mailer_lite.symfony_mailer_lite_transport.smtp']['label'] = 'DDEV SMTP';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.smtp']['plugin'] = 'smtp';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.smtp']['configuration']['user']='';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.smtp']['configuration']['pass']='';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.smtp']['configuration']['host']='localhost';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.smtp']['configuration']['port']='1025';

If you only have a sendmail transport type, then you can use this in sites/default/settings.ddev.php to make your local ddev instance use Mailpit:

// Override drupal/symfony_mailer_lite default config to use Mailpit
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['plugin'] = 'smtp';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['user'] = '';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['pass'] = '';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['host'] = 'localhost';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['port'] = '1025';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['query']['verify_peer'] = true;
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['query']['local_domain'] = '';
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['query']['restart_threshold'] = null;
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['query']['restart_threshold_sleep'] = null;
$config['symfony_mailer_lite.symfony_mailer_lite_transport.sendmail']['configuration']['query']['ping_threshold'] = null;

Update: This does work. But DDEV seems to recreate the settings.ddev.php on startup, so you'll loose these settings the next time you start your ddev project. Luckily, all our projects include a different settings file based on the environment (local, development, production) so I was able to simply put these settings into our settings.local.php file.

dpi’s picture

Just adding 2c since I was linked this, and following on @mxr576's #4:

Ive found creating all your transports as config, exporting them as normal works well.
Configure your default transport to use your local/development server.
Then, use env detection with env vars or whatever in a settings.php, switch the active transport via config overrides:

$config['symfony_mailer_lite.settings']['default_transport'] = 'myprodtransportidgoeshere';

Keep in mind config overrides are not visible in the UI. So you can use drush cget --include-overridden symfony_mailer_lite.settings to verify your changes are active.

berdir’s picture

@dpi: The default transport shown on the overview is actually considering the overridden value as it is not an edit form, it's loading it as regular immutable config with overrides. On the other site drush cget reads config directly and does not include overrides, if you want to see overrides, you need to use drush core-cli/drush ev and then access it with \Drupal::config('symfony_mailer_lite.settings']->get().

dpi’s picture

The default transport shown on the overview is actually considering the overridden value as it is not an edit form

Ah okay, makes sense.

On the other site drush cget

Like I mentioned, the --include-overridden flag will include the overrides.

seanr’s picture

Confirmed I'm getting the overrides correct (we should be sending via smtp), but I'm still getting this:

An attempt to send an e-mail message failed, and the following error message was returned : Error creating transports: Unsupported sendmail command flags "/opt/mailhog/mhsendmail"; must be one of "-bs" or "-t" but can include additional flags.

drush @tcf.stage  cget --include-overridden symfony_mailer_lite.settings
_core:
  default_config_hash: EyOEXkLJD4vYGpK5wicdBSwBorOJgslf_tyscMgeN0Q
default_transport: smtp
drush @tcf.stage  cget --include-overridden symfony_mailer_lite.symfony_mailer_lite_transport.smtp
uuid: e313ee9e-2ca1-42ea-ac39-a27bf2f56326
langcode: en
status: true
dependencies: {  }
id: smtp
label: SMTP
plugin: smtp
configuration:
  user: ''
  pass: ''
  host: 127.0.0.1
  port: '1025'
  query:
    verify_peer: false
    local_domain: ''
    restart_threshold: null
    restart_threshold_sleep: null
    ping_threshold: null

With swiftmailer on our staging server, it was 127.0.0.1, not localhost. Could that make a difference?

gresko8’s picture

I had this error too and fixed it by deleting the native transport method (had SMTP chosen as default and did not really need the native). Looks like the default state was not respected maybe, could be a bug.