Sendmail transport won't work with Mailhog/MailPit

Created on 15 October 2023, about 1 year ago
Updated 26 June 2024, 6 months ago

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!

πŸ’¬ Support request
Status

Closed: works as designed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States JCL324 Portland, OR

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

Comments & Activities

  • Issue created by @JCL324
  • πŸ‡ΊπŸ‡ΈUnited States yujiman85

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

  • πŸ‡¨πŸ‡¦Canada Jaypan

    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:

      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
  • Status changed to Closed: works as designed about 1 year ago
  • πŸ‡­πŸ‡ΊHungary mxr576 Hungary

    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.

  • πŸ‡§πŸ‡ͺBelgium flyke

    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';
  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    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.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    @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/drussh ev and then access it with \Drupal::config('symfony_mailer_lite.setting']->get().

  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    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.

  • πŸ‡ΊπŸ‡ΈUnited States seanr

    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?

Production build 0.71.5 2024