2

I am attempting to setup so I can mail from Raspbian.

When I attempt to send I get an error ssmtp: Cannot open smtp.gmail.com:587 (I also tried port:465)

I have set "Access for less secure apps" on Google and can send/receive from the account on Thunderbird.

I have installed ssmtp and configured /etc/ssmtp/ssmtp.conf to contain:-

# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
[email protected]

# 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=smtp.gmail.com:587

[email protected]
AuthPass=xxxxxxxxxxxxxx
UseTLS=YES
UseSTARTTLS=YES

# Where will the mail seem to come from?
rewriteDomain=gmail.com

# The full hostname
[email protected]

# 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

I have also configured /etc/ssmtp/revaliases to contain:-

# 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]:smtp.gmail.com:587

Any suggestions?


Edit The settings above based on https://wiki.archlinux.org/index.php/SSMTP

I have done some further testing.

  1. I selected a different SMTP server, which worked. (I do not want to use this, as it is only available when directly connected to my ISP.)

  2. I tried setting an Application Specific password, and got the response"The setting you are looking for is not available for your account". (Presumably because this account does not have 2-factor authentication.)

The gmail account I am trying to use was specifically created to send messages from the Raspberry Pi.

3
  • Setting up an application password is one of the ways, as far as I can remember; it has been a good while ago. Apr 19, 2017 at 7:48
  • Cannot open sounds like a network level issue, can you use tcpdump or wireshark to see if the packets are even getting to google?
    – thrig
    Apr 19, 2017 at 14:20
  • @tripleee I changed the hostmail and it worked. If you post as answer I will accept! I had used a guide from a reputable book, which had a full example, and this used email address! The Arch site said "# The full hostname. Must be correctly formed, fully qualified domain name or GMail will reject connection. hostname=yourlocalhost.yourlocaldomain.tld" but I misread this, as email.
    – Milliways
    Apr 20, 2017 at 5:19

2 Answers 2

3

This is very easy to accomplish:

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

EXCERPT:

Install ssmtp 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
[email protected]
AuthPass=testing123
UseTLS=YES

Send a one-liner like so:

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

Couldn't be simpler.

2

The hostname assignment looks wrong. You probably want hostname=raspberry.pi or something like that. (Ideally, your host has a public DNS name, and you should use that.) It should not be an email address.

2
  • I have not examined the sources but I imagine it's only actually used in the HELO/EHLO in which case it doesn't crucially matter what exactly you put there. It will end up in a Received: header so it's helpful if it somehow uniquely identifies your host.
    – tripleee
    Apr 20, 2017 at 6:09
  • The various settings I used actually appeared in Received:, although my ISP removed the @ and substituted ?. Google just refused the request. I am now using my domain name.
    – Milliways
    Apr 20, 2017 at 6:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .