ssmtp is a nice and simple solution for sending emails from the command line etc.

Installing


sudo apt-get install ssmtp
sudo apt-get install mailutils

Now edit the SSMTP configuration file


sudo nano /etc/ssmtp/ssmtp.conf

It needs to include this:


root=postmaster
mailhub=smtp.gmail.com:587
hostname=raspberrypi
AuthUser=AGmailUserName@gmail.com
AuthPass=TheGmailPassword
FromLineOverride=YES
UseSTARTTLS=YES

Save and exit

Sending an email


echo "Hello world email body" | mail -s "Test Subject" recipientname@domain.com

 

Sending A File

Install mpack


sudo apt-get install mpack

To send a file


mpack -s "Test" /home/pi/some_folder/somefile.ext recipientname@domain.com

 





USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.

Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.

  • PpFlo

    TX! Usefull and simple!

  • Paul

    doesn’t work for me. something’s missing.

  • Brent Lessard

    followed steps exactly, works for me

  • Hans

    Works fine on my system, except for messages addressed to recipient ‘root@localhost’.

    System: raspberrypi 2.

    Does anybody knows to fix this issue?

    thans in advance.

  • Old Raggare

    I followed all the steps.
    I’m getting an error:
    mail: cannot send message: Process exited with a non-zero status

  • lalwanis

    Appreciate your effort to make using pi very easy…
    Thanks for your efforts

  • priya

    Sir
    When we work out all the commands it shows error –
    send-mail:cannot open stpm.gmail.com:587

  • Roxysteve

    One problem that may be hiding under the “returned non-zero status” error is that an existing GMAIL account may refuse the connection as insufficiently secure.

    I made a new account just for the pi and that seemed to clear up the issue for me. I did not have to reset any security settings on the new account and was unwilling to relax the security I had set up on my main GMAIL account.

    Everyone should look at the various Linux ssmtp install guides to understand how to secure your ssmtp.conf file (where your GMAIL password sits in plaintext!).

  • Mohammad Hameed

    I had the same issue mail: cannot send message: Process exited with a non-zero status.

  • Mohammad Hameed

    Allowing less secure apps in gmail solves the problem – mail: cannot send message: Process exited with a non-zero status

  • Feri

    Hi! Not good in english and not good in Linux – but: How to send emails in this manner directly from programm written in C language? Pls, little code example. Thx.
    Feri

  • eamant

    use smtp.gmail.com:465

  • eamant

    Can anyone help me by sending an example in python?

    thanks a lot

  • 1234Garrett1234

    Can I sned an e-mail with attachment and body text?

  • Mthylynn

    Check that your permissions are correct. that looks like a resolution problem. If there is no POP server, it won’t receive any messaging.

  • Mthylynn

    Create a gmail account for the device (MyRPI@gmail.com) or something like that, then use that as the sending email, get an API key from gmail for the security and that may help.

  • lemanoman

    If you got the error : “mail: cannot send message: Process exited with a non-zero status”, you must to activate the less secure apps on you google account: “https://www.google.com/settings/security/lesssecureapps”