Skip to content

Latest commit

 

History

History
98 lines (61 loc) · 2.71 KB

emails.md

File metadata and controls

98 lines (61 loc) · 2.71 KB

How to send emails in Drupal?

Sending mails is as hard as having a working printer.

Requirements

First, please evaluate what is the actual need for sending emails in a Drupal site:

  1. Just Drupal user password resets (Forgotten password)
  2. 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:

Stonehenge

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

Lagoon

  • In Lagoon we can use "SMTP relay" technique as a transport

Lagoon SMTP settings

Wodby

  • In Lagoon we can use "SMTP relay" technique as a transport
  • Read more on Wodby docs

Wodby SMTP settings

Custom

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).

Testing

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 yourself
  • from@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