Problems using mailhog sendmail with Native Transport

Created on 27 April 2022, over 2 years ago
Updated 12 November 2023, about 1 year ago

Problem/Motivation

We are trying to switch our Simplenews and site emails from Mail System and Swiftmailer to Symfony Mailer with as little disruption as possible.

We use mailhog (and thus mhsendmail) to capture emails on our dev system running in a Parallels VM provisioned using Drupal-VM which has mailhog provisioning built in.

On our dev system today we configure php.ini >> sendmail_path = /opt/mailhog/mhsendmail an on our our live system sendmail_path is the default sendmail binary. In this way we maintain an identical Drupal configuration thus eliminating potential errors by minimising the configuration differences between dev and live systems.

Switching to Symfony Mailer whilst retaining our current php.ini settings and choosing SM’s Native Transport produces no errors yet neither does it produce any email output! We tried various combinations of -t -bs -i (mh)sendmail parameters with varying degrees of failure.

We can verify that mailhog is working as mail sent from the Linux command line correctly invokes mhsendmail and messages are routed to the mailhog UI for inspection.

We can verify that we have imported our swiftmailer configuration OK as, since mailhog uses port 1025, we can send our simplenews email messages to mailhog by using Symfony Mailer’s SMTP Transport specifying host 127.0.0.1 and port 1025.

But this does not meet our objective of keeping dev and live Symfony Mail configuration the same as we would prefer to use Native Transport on both dev and live systems.

Remaining tasks

I don’t have the specialised knowledge to know exactly what further diagnostic info I can provide to determine why Symfony Mailer’s Native Transport is not offering what we wer expecting.

🐛 Bug report
Status

Closed: works as designed

Version

1.0

Component

Miscellaneous

Created by

🇬🇧United Kingdom iainH

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States mrweiner

    It seems that #8 no longer works as expected on platform.sh. I'm now getting an error Error sending email: The "sendmail://:?command=%2Fusr%2Fsbin%2Fsendmail+-t+-i+-t" mailer DSN is invalid.. It seems like they've maybe added -t -t to their sendmail path. However, just using ini_get('sendmail_path') doesn't work either. Not sure what's going on...maybe an encoding issue?

  • 🇪🇸Spain joe_carvajal Seville (Spain)

    Thank you @mrweiner for #8 and #16 for the platform.sh config. They made my day.

  • 🇮🇹Italy kopeboy Milan

    Emails are not sent if on local with ddev.
    They add these settings automatically (at present):

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

    With mailhog module disabled, emails are not sent.
    If you comment out all those ddev settings, flush cache, and I try sending the test email, you get error:
    Error sending email: Connection to "process /usr/sbin/sendmail -bs" has been closed unexpectedly.

  • 🇺🇸United States jcmartinez Raleigh, NC, USA

    If you work inside Lando or another similar environment, your localhost may have a different name.

    In my case, using Lando, this is how I make it work:

    // To use Symfony Mailer with Mailhog locally.
    $config['symfony_mailer.mailer_transport.sendmail']['configuration']['query']['command'] = ini_get('sendmail_path') . ' -t';
    $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']='mailhog';
    $config['symfony_mailer.mailer_transport.sendmail']['configuration']['port']='1025';
    
Production build 0.71.5 2024