Sending mails is as hard as having a working printer.
First, please evaluate what is the actual need for sending emails in a Drupal site:
- Just Drupal user password resets (Forgotten password)
- Email content, order confirmation etc (related to business logic)
If use case is the 1st, then probably there is no need to install any modules to Drupal.
For the 2nd; there are some modules which might be needed:
- Mail System
↗️ to control what is used as Formatter and Sender - Mime Mail
↗️ to use HTML mails
On your local environments you want to send emails to Mailpit.
This can be done e.g. with adding this ENV variable to your Docker service having PHP:
On druidfi Docker images (app service):
PHP_SENDMAIL_PATH: /usr/sbin/sendmail -S host.docker.internal:1025 -t
On Lagoon images (cli and php service):
SSMTP_MAILHUB: host.docker.internal:1025
On Wodby images (php service):
PHP_SENDMAIL_PATH: /usr/sbin/sendmail -S host.docker.internal:1025
SSMTP_MAILHUB: host.docker.internal:1025
- In Lagoon we can use "SMTP relay" technique as a transport
- In Lagoon we can use "SMTP relay" technique as a transport
- Read more on Wodby docs
In a custom hosting environment like virtual server or other custom env you can try to configure sendmail to use an external SMTP service.
sendmail_path
setting can be found from php.ini file(s).
You can test sendmail working correctly with login to PHP container and running following commands (example):
to@druid.fi
should be you - send test message to yourselffrom@druid.fi
should be the validated sender domain or email in Mailjet/AWS/Sendgrid etc
Using PHP (which uses sendmail):
php -r 'mail("to@druid.fi", "Test subject", "This is our test message", "From: from@druid.fi"); echo "sent";'
Or using verbose mode:
php -d "sendmail_path=/usr/sbin/sendmail -v -S host.docker.internal:1025 -t" -r 'mail("to@druid.fi", "Test subject", "This is our test message", "From: from@druid.fi");'
Using Sendmail directly:
First create a file called email.txt
with following content:
From: sender@example.com
To: recipient@example.com
Subject: Email Subject
This is the body of the email.
It can contain multiple lines of text.
cat email.txt | sendmail -S host.docker.internal:1025 -v -f to@druid.fi from@druid.fi