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
Comment #2
yujiman85 commentedAny update on this? I'm having a very similar issue.
Comment #3
jaypanI just hit this issue in DDev. To configure this module to work with Mailpit in DDev, you can do the following:
Click save
Comment #4
mxr576This 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).
Therefore I'd suggest registering multiple transports (#3 is also a valid transport config) and switching the default transport in
symfony_mailer_lite.settingsconfig 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.
Comment #5
flyke commentedAdd this in your sites/default/settings.ddev.php if you are using SMTP transport:
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:
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.
Comment #6
dpiJust 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.settingsto verify your changes are active.Comment #7
berdir@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().
Comment #8
dpiAh okay, makes sense.
Like I mentioned, the
--include-overriddenflag will include the overrides.Comment #9
seanrConfirmed 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.
With swiftmailer on our staging server, it was 127.0.0.1, not localhost. Could that make a difference?
Comment #10
gresko8 commentedI 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.