9

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" me2@gmail.com

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

or

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:

ssmtp.conf

#
# 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?
#rewriteDomain=

# The full hostname
hostname=raspberrypi

# 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
FromLineOverride=YES


root=me@gmail.com
mailhub=smtp.gmail.com:587
AuthUser=me@gmail.com
AuthPass=mypass
UseSTARTTLS=YES

revaliases

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

root:me@gmail.com:mail.google.com:587
4

You probably have it figured out by now, but I noticed in your ssmtp.conf file, you have: root=me@gmail.com

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

I left it like that and just changed the other me@gmail.com parts and it works for me. Thanks for your help though, it got me on my way...

2

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."

1

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

1

I think you are looking for this:

https://unix.stackexchange.com/questions/363814/simplest-way-to-send-one-line-mail-out-via-command-line-using-gmail

EXCERPT:

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:

root=rpi3abc@gmail
mailhub=smtp.gmail.com:465
FromLineOverride=YES
AuthUser=rpi3abc@gmail.com
AuthPass=testing123
UseTLS=YES

Send a one-liner like so:

echo "Testing...1...2...3" | ssmtp myusername@gmail.com

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:

https://unix.stackexchange.com/questions/381131/simplest-way-to-send-mail-with-image-attachment-from-command-line-using-gmail

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 importantdude@gmail.com

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, privacy policy and cookie policy

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