10

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
SDsolar
  • 2,348
  • 8
  • 25
  • 43
omega
  • 201
  • 1
  • 2
  • 3
  • 2
    This is not a specific Raspberry question try on:-http://unix.stackexchange.com/ – Milliways Dec 20 '13 at 22:42
  • take a look at this it http://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. – Steve Robillard Dec 21 '13 at 01:02
  • How do I get the app specific password?? – omega Dec 21 '13 at 02:46
  • Have you tried with UseSTARTTLS=NO? – goldilocks Dec 21 '13 at 11:50
  • yes, but it still didn't work. – omega Dec 21 '13 at 18:15
  • if you are not using 2 factor authorization with Google you can use the regular password you use when accessing gmail via your browser, If you are using 2 factor auth. and need an app specific password log into your google account, then go to your account page (click on your avatar in the upper right) and select account, then choose the security tab, and finally 2-step verification settings. from this page you can mange your app specific passwords. – Steve Robillard Dec 25 '13 at 03:51

4 Answers4

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

Dave
  • 41
  • 2
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."

Oliver T.
  • 21
  • 1
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.

SDsolar
  • 2,348
  • 8
  • 25
  • 43