Sending mail with the Raspberry Pi

Raspian, the default linux distribution for the Raspberry Pi does not install a mail server by default, so the raspberry cannot send mails. For raspberries running headless, i.e. without a monitor attached, mailing would be a good feauture, e.g. to report pending package updates, etc. So here is a simple way to enable sending mails from the raspberry without installing a full featured mail server.

You can install a full-featured mail server like postfix, but this would consume too much resources on the raspberry and for sending update notifications you would not need all its features. A more simple way is to use the mail server of your internet provider or a service like GMX or similar. You only need to tell the raspberry to forward the outgoing mails to the correct mail server. This can be done by installing the packages ssmtp and heirloom-mailx:

apt-get install ssmtp heirloom-mailx

The ssmtp package is used to transport your mails to your provider and needs to be configured by editing /etc/ssmtp/ssmtp.conf. There you add the name of your mail server, your username and password and enable TSL to encrypt the connection to your provider (if it supports encryption). This is my ssmtp.conf configuration file:

# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named

# Where will the mail seem to come from?
# The full hostname

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address

# Use SSL/TLS before starting negotiation

# Username/Password

The heirloom-mailx package is installed to be able to send mails on the command-line. You can test your installation like this:

echo "mail from your raspberry" | \
mail -s "Testmail"

If this does not work, you can call ssmtp directly and get debug output this way:

echo "Test" | \
sendmail -v

This will print out the communication with the mail server of your provider.

2 thoughts on “Sending mail with the Raspberry Pi

  1. In fact, you do not need to install anything.
    Exim is already installed on Raspbian, but it is configured by default to stay local.
    You just have to change the file “update-exim4.conf.conf”

  2. Pingback: How to send email from Raspberry Pi | Giovanni's Blog

Leave a Reply

Your email address will not be published. Required fields are marked *