Send emails with attachements from the Linux command line.

If you are like me and you are running your Raspberry Pi headless, and don’t want to start up X windows to send a simple email. You are in luck, as this can easily be done from the command line. And it is very easy to setup.

Note; This is only to send email, and not receive.


– Install SSMTP

pi@raspberrypi ~ $sudo apt-get update
pi@raspberrypi ~ $sudo apt-get install ssmtp


-Configure SMTP

pi@raspberrypi ~ $ sudo nano /etc/ssmtp/ssmtp.conf

Add add these lines;

root=username@gmail.com
mailhub=smtp.gmail.com:465
rewriteDomain=gmail.com
AuthUser=username
AuthPass=password
FromLineOverride=YES
UseTLS=YES


Use your email address for root, and your gmail username and password for AuthUser and AuthPass.



To send an email
To send an email, run SSMTP with the recipients name.
SSMTP will then wait for you to type your email. It has to be formatted as shown below. And once done, press Ctrl-D to send.

pi@raspberrypi ~ $ ssmtp mail.address@example.com
subject: this is a test
hellow world!
pi@raspberrypi ~ $


Send an attachment
It is also possible to send attachments. This can be done using mpack


Install mpack

pi@raspberrypi ~ $sudo apt-get install mpack


To send a file with an attachment;

pi@raspberrypi ~ $ mpack -s subject picture.png mail.address@example.com

Leave a Reply