Friday, December 26, 2014

Implementing SSMTP to send email via command line

SSMTP is a program which delivers email from a local computer to a configured mailhost (mailhub). It is not a mail server (like feature-rich mail server sendmail) and it does not receive mail, expand aliases or manage a queue. One of its primary uses is for forwarding automated email (like system alerts) off your machine and to an external email address. Check https://wiki.archlinux.org/index.php/SSMTP for more information.


1. Remove sees and postfix (if it is currently installed on your system)

pacman -Rnd sees postfix

2. Install ssmtp

pacman -S ssmtp

3. Configure ssmtp

vim /etc/ssmtp/ssmtp.conf

#
# /etc/ssmtp.conf -- a config file for sSMTP sendmail.
#
# The person who gets all mail for userids < 1000
root=postmaster
mailhub=smtp.gmail.com:587
rewriteDomain=gmail.com
hostname=localhost
UseTLS=Yes
UseSTARTTLS=Yes
# Username/Password
AuthUser=meric.mara@gmail.com
AuthPass=
FromLineOverride=yes


4. Check permission
chmod 640 /etc/ssmtp/ssmtp.conf
chown root:mail /etc/ssmtp/ssmtp.conf

5. Users who can send mail
gpasswd -a mmara mail

6. Check your Google Less secure apps settings
https://www.google.com/settings/security/lesssecureapps



7. Send test mail

echo test | mail -v -s "HELLO WORLD" tousername@somedomain.com

That's it!

No comments: