Send an email from your Raspberry Pi

If you have a Raspberry used as a server, an automation tool or anything else it may be useful to get some news from him regularly. With sSMTP you can easily send email via the SMTP server from an Internet provider (here Google as an example)

raspberry send email gmail ssmtp

  1. Update distribution
    apt-get update && apt-get upgrade -y
  2. Install sSMTP, mpack (to encode and decode any attachments) and mailutils that contains the command mail to send / check emails.
    apt-get install -y ssmtp mailutils mpack
  3. Configure ssmtp by editing the file /etc/ssmtp/ssmtp.conf. Add the following lines to the end of file
  4. You may need to create a specific password for the application, Gmail password generating an error for the authentication 534 :
    Aug 12 09:23:19 squid sSMTP[21051]: Authorization failed (534 5.7.9 i1sm6469057wjq.42 - gsmtp)

    In this case, visit this page and following the instructions you will have a password 16 characters that will replace your current password in the configuration file /etc/ssmtp/ssmtp.conf

  5. Now test your configuration :
    echo "Hello" | mail-s "This is the subject line"
  6. You can redirect the emails generated by the system to an external email address through the file /etc/aliases. For example, by adding the following lines in the file
    # /etc/aliases
    www: root

    Mails generated to the user www will be redirected to the user root which will send emails to your Gmail external address.

  7. Finally last option if you want a name “readable” as the source of your emails, consider using the chfn command to change the name that will be displayed :
    chfn -f "My display name" root

You can now simply and quickly send emails through Gmail SMTP

You may also like...