phpmailer_smtp
Send emails via SMTP using the latest PHPMailer library.
The only requirements are the Mail System module and an SMTP service.
Features
- Send email via SMTP using an external service
- Supports HTML emails, attachments and inline images
- RFC compliant ensuring robust email delivery
- Doesn't reinvent the wheel - uses the PHPMailer library wherever possible
- Debugging options
- Advanced SMTP settings
Requirements
- Access to an SMTP server
- The Mail System module.
- PHPMailer library - installed via composer, see below
Installation
composer require drupal/phpmailer_smtp
This installs the module and the PHPMailer library. Enable the module as usual.
If you can't use composer Ludwig is supported.
Configuration
Configure PHPMailer SMTP
SMTP server configuration
Administer -> Configuration -> System -> PHPMailer SMTP
The most secure port is 465 which uses implicit encryption so no part of the communication is in plain text. For this port, select "SSL/TLS" as the encryption protocol.
The "STARTTLS" option is used to upgrade a plain text connection to use TLS. This is used with port 587 which requires an explicit request to change to an encrypted connection and is less secure than the fully encrypted connection on port 465.
Email format
Administer -> Configuration -> System -> PHPMailer SMTP -> Format
Selecting "Plain text" will force all emails to be plain text.
Install and Configure Mail System
composer require drupal/mailsystem
Enable the mail system module then configure:
Administer -> Configuration -> System -> Mail System.
Select "PHPMailer SMTP" as "Sender" under "Default Mail System" and "Module-Specific Configuration" as required.
Select "PHPMailer SMTP" as the Formatter
OAuth2
OAuth2 is supported via basic plugins. For an example using Azure, see PHPMailer OAuth2. Review the code in the module to find out how it works so you can implement your own provider.
The PHPMailer library supports league/oauth2-client providers:
As of PHPMailer 6.6.0, the library now accepts anything that implements the OAuthProviderInterface. This includes Google's OAuth classes.
Optional
Performance
To improve performance on page load emails can be queued prior to sending.
- Queue Mail will queue emails which can then be sent later on a cron run.
- Ultimate Cron allows for fine-grained control over cron runs. For example using Queue Mail, email can be stored and sent sent every minute while other tasks are performed once an hour.
Security
For better security, SMTP credentials can be stored outside normal config.
- Key can override any configuration value with a key to store configuration values more securely. See Overriding configuration
- Encrypt adds encryption support with a patch for the Key module: #2980072: Encrypt key value