Im new to raspberry pi.

I installed the raspian OS on it. I want to send emails from it using my gmail account. I want to send from the command line interface and from php scripts.

I followed this guide. http://iqjar.com/jar/sending-emails-from-the-raspberry-pi/

I did steps 1,2,3,4 from the link.

When I send an email using the code below using

echo "Test text" | mail -s "Test Mail" [email protected]

nothing happens, there is nothing printed on the screen, and I don't get the email.

On "revaliases", if I replace "mail.google" with "smtp.gmail", then I get back a message saying

send-mail: Cannot open mail.google.com:587


send-mail: Server didn't like our AUTH LOGIN (530 5.7.0 Must issue a STARTTLS command first. ml2sm3592928igb.10 - gsmtp)

Does anyone know how to fix this? Thanks

Here are the two files below:


# Config file for sSMTP sendmail
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
# root=postmaster

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

# 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

[email protected]
[email protected]


# sSMTP aliases
# Format:   local_account:outgoing_address:mailhub
# Example: root:[email protected]:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.

root:[email protected]:mail.google.com:587
  • 2
    This is not a specific Raspberry question try on:-unix.stackexchange.com
    – Milliways
    Commented Dec 20, 2013 at 22:42
  • take a look at this it raspberry.znix.com/2013/03/postfix-better-solution-for-rpi.html. Also if you use 2factor auth with google you need to use a app specific password not the password you use to log into gmail over the web. Commented Dec 21, 2013 at 1:02
  • How do I get the app specific password??
    – omega
    Commented Dec 21, 2013 at 2:46
  • Have you tried with UseSTARTTLS=NO?
    – goldilocks
    Commented Dec 21, 2013 at 11:50
  • yes, but it still didn't work.
    – omega
    Commented Dec 21, 2013 at 18:15

4 Answers 4


You probably have it figured out by now, but I noticed in your ssmtp.conf file, you have: [email protected]

However, in the link you posted, it says: root=postmaster

I left it like that and just changed the other [email protected] parts and it works for me. Thanks for your help though, it got me on my way...


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" "dc_eximconfig_configtype='satellite' etc."


I had the very same issue.

It turned out that gmail blocked the request because the smtp client is blacklisted as not secure (probably it's one of the clients affected by the heartbleed bug)

You can allow less secure clients on your gmail settings here: https://support.google.com/accounts/answer/6010255?hl=en

or, better yet, upgrade to a newer version of the smtp client, if possible


I think you are looking for this:



The answer to sending one-line messages is to use ssmtp

Install it with the following commands:

sudo apt-get update
sudo apt-get install ssmtp

Then go into /etc/ssmtp and edit ssmtp.conf to look like this:

[email protected]

Send a one-liner like so:

echo "Testing...1...2...3" | ssmtp [email protected]

You can also cat a whole file and pipe it in as the message.

If you want to send image files as attachments, then you want this one:


It is basically the same, but adds:

Install mpack:

apt-get update
sudo apt-get install mpack

Then send an image as an attachment like so:

mpack -s "P&L Proj 2018" /home/pi/Desktop/finance/PL18.png [email protected]

If the file is in the current directory, then it is not necessary to use a fully-qualified path to the attachment.

And if used in cron remember that the jobs always run in the user's home directory, so it is good practice to use a full directory path to the attachment file.

Voila. That's it. Couldn't be easier.

It works both on Raspbian and all the later versions of Ubuntu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.