Basic mail for your Drupal site with msmtp

Topics: 

Drupal requires an SMTP client to send mail. You could install a full-featured mail transfer agent (MTA) like Postfix on your (virtual) machine to serve this function, but it's overkill if you only need to send mail through PHP. Instead, install msmtp. It's lightweight and much simpler to configure.

These instructions assume that you have a Debian-based operating system (OS) such as Ubuntu Server. There may be minor differences for other OS types.

Install msmtp

sudo apt-get install msmtp ca-certificates

Configure it

Create a new configuration file:

sudo vi /etc/msmtprc

...with the following configuration information:

# Set defaults.
defaults

# Enable or disable TLS/SSL encryption.
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt

# Set up a default account's settings.
account default
host <smtp.example.net>
port 587
auth on
user <username@example.net>
password <password>
from <address-to-receive-bounces@example.net>
logfile /var/log/msmtp/msmtp.log

You need to put your own configuration information within each "<" and ">". For host/username/password, use your normal credentials for sending mail through your mail provider.

Tell PHP to use it

sudo vi /etc/php5/conf.d

Add this single line:

sendmail_path = /usr/bin/msmtp -t

Set up logging

sudo mkdir /var/log/msmtp
sudo chown www-data:adm /var/log/msmtp
sudo vi /etc/logrotate.d/msmtp

Add these lines to the new file:

/var/log/msmtp/*.log {
  rotate 12
  monthly
  compress
  missingok
  notifempty
}

If you'd like to be able to view the logs as yourself, you should add yourself to the www-data group.

Comments

Add new comment