Issue mail messages from Debian/Ubuntu command line
This is accomplished by using the ssmtp package of Linux system.
1. install smtp package for the linux system:
sudo apt update
sudo apt install mailutils
sudo apt install ssmtp
sudo apt install postfix
2. edit the /etc/ssmtp/ssmtp.conf file, an example of ssmtp.conf file should be seen like this:
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=i2r.nbt.linux@gmail.com
# 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
# Where will the mail seem to come from?
rewriteDomain=gmail.com
# The full hostname
hostname=gmail.com
# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes
# Username/Password
AuthUser=i2r.nbt.linux
AuthPass=neuroi2r
AuthMethod=LOGIN
# 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
3. Test the smtp mail service.
echo "Test mail" | mail -v -s "Testing" huangs@i2r.a-star.edu.sg
Sometime the gmail account need to change the setting, namely the security of mail account.
This procedure works for gmail. But for office 365, initial testing failed. May need to change setting but no chance to do it.
No comments:
Post a Comment