Raspberry PI - send mail from the command line using the GMAIL smtp server

How can I send an email from a Raspberry Pi using my gmail account?

I want to send a message from the command line and use this method in my scripts.

Envirenment:

Hardware: Raspberry PI 3
OS: Jessie
SMTP: smtp.gmail.com
+4
source share
1 answer

I use this method on my Raspberry Pi 3 devices:

Google Account Settings

  • Log in to your gmail account
  • Go to: Settings → Accounts and Import → Other Google Account Settings
  • Go to: Personal Information and Privacy → Account Overview
  • : →

SSMTP
  sudo apt-get install ssmtp

conf
  sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak

conf ( vi )
  sudo vi /etc/ssmtp/ssmtp.conf


root=your_account@gmail.com
mailhub=smtp.gmail.com:587

FromLineOverride=YES
AuthUser=your_account@gmail.com
AuthPass=your_password
UseSTARTTLS=YES
UseTLS=YES

# Debug=Yes

conf

sudo groupadd ssmtp
sudo chown :ssmtp /etc/ssmtp/ssmtp.conf

, , " "... ssmtp : sudo find/-name "ssmtp"

sudo chown :ssmtp /usr/sbin/ssmtp
sudo chmod 640 /etc/ssmtp/ssmtp.conf
sudo chmod g+s /usr/sbin/ssmtp

( )

echo "This is a test" | ssmtp recipient.address@some_domain.com

printf "To: recipient.address@some_domain.com\nFrom: RaspberryPi3\nSubject: Testing send mail from Raspberry\n\nThis is test. Best Regards!\n" | ssmtp -t

test.txt
:

To: recipient.address@some_domain.com
From: your_account@gmail.com
Subject: Testing send mail from Raspberry

This is test mail (body)

Best Regards!

ssmtp recipient.address@some_domain.com < test.txt

:)

+12

Source: https://habr.com/ru/post/1647994/


All Articles