4
如何使用我的gmail帳戶從Raspberry Pi發送電子郵件?Raspberry PI - 使用GMAIL smtp服務器從命令行發送郵件
我想從命令行發送郵件並在腳本中使用此方法。
Envirenment:
Hardware: Raspberry PI 3
OS: Jessie
SMTP: smtp.gmail.com
如何使用我的gmail帳戶從Raspberry Pi發送電子郵件?Raspberry PI - 使用GMAIL smtp服務器從命令行發送郵件
我想從命令行發送郵件並在腳本中使用此方法。
Envirenment:
Hardware: Raspberry PI 3
OS: Jessie
SMTP: smtp.gmail.com
我用我的樹莓派3設備,這個方法:
谷歌帳戶設置
安裝SSMTP
sudo apt-get install ssmtp
保存原始的con f文件
sudo mv /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bak
創建新配置文件(用vi或一些其他文本編輯器)
sudo vi /etc/ssmtp/ssmtp.conf
文件內容
[email protected]
mailhub=smtp.gmail.com:587
FromLineOverride=YES
[email protected]
AuthPass=your_password
UseSTARTTLS=YES
UseTLS=YES
# Debug=Yes
安全的conf文件
sudo groupadd ssmtp
sudo chown :ssmtp /etc/ssmtp/ssmtp.conf
如果你有這一步,如「錯誤」不能訪問「」 ......你必須找到ssmtp中的文件,並使用該路徑:須藤查找/ -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 [email protected]_domain.com
或
printf "To: [email protected]_domain.com\nFrom: RaspberryPi3\nSubject: Testing send mail from Raspberry\n\nThis is test. Best Regards!\n" | ssmtp -t
從文件測試發送郵件。具有類似內容的txt
Make文件:
To: [email protected]_domain.com
From: [email protected]
Subject: Testing send mail from Raspberry
This is test mail (body)
Best Regards!
現在你可以從文件
ssmtp [email protected]_domain.com < test.txt
這就是發送郵件的所有:)
你應該提交這代碼審查 - 你一直提交回答作爲問題 – dbmitch
@dbmitch http://stackoverflow.com/help/self-answer – Nick
使用雙引號(如圖所示)的命令行的printf形式導致錯誤:-bash:!\ n :未找到事件 在整行內部使用單引號(在printf和| )而是,它的工作原理。 – tim11g