Home
About
Resume
Projects
Links
Blog
Back to Contents
# sSMTP to send automated email #### Introduction [sSMTP](https://wiki.debian.org/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 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. #### Installation & Configuration **1. Install by APT** `sudo apt install ssmtp mailutils` **2.1 Configure sSMTP (with free, custom domain email provider, [zoho.com](https://www.zoho.com))** `nano /etc/ssmtp/ssmtp.conf` ```bash # # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=username@myDomain.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.zoho.com:465 # Where will the mail seem to come from? #rewriteDomain= # The full hostname hostname=myDomain.com # 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 AuthUser=username@myDomain.com AuthPass=******** UseTLS=YES ``` AuthPass is **not** the login password. One can be created in the [Security > Application-Specific Passwords](https://accounts.zoho.com/home#security/security_pwd) section. In case of encountering `sendmail: 553 Relaying disallowed`, configuring **revaliases** may solve the problem: `nano /etc/ssmtp/revaliases` ```bash # sSMTP aliases # # Format: local_account:outgoing_address:mailhub # # Example: root:your_login@your.domain:mailhub.your.domain[:port] # where [:port] is an optional port number that defaults to 25. root:username@myDomain.com:smtp.zoho.com:465 ubuntu:username@myDomain.com:smtp.zoho.com:465 ``` **2.2 Configure sSMTP (with [gmail](https://mail.google.com/))** ```bash # # Config file for sSMTP sendmail # # The person who gets all mail for userids < 1000 # Make this empty to disable rewriting. root=username@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= # The full hostname hostname=gmail.com # 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 AuthUser=username@gmail.com AuthPass=******** UseSTARTTLS=YES UseTLS=YES ``` Again, AuthPass is **not** the login password. You can create one with the following steps: - Access [Google Account Security page](https://myaccount.google.com/security) - **Allow** Less secure app access - Setup 2-Step Verification - Setup App passwords **(Only available when 2-Step Verification is setup)** #### Verify the Installation `echo "Subject: hello" | sendmail test@example.com` Further example, please visit [16 COMMAND EXAMPLES TO SEND EMAIL FROM THE LINUX COMMAND LINE](https://blog.edmdesigner.com/send-email-from-linux-command-line/). #### Install Add-on ([mpack](https://linux.die.net/man/1/mpack)) [Optional] With **mpack**, you may attach a file in MIME format to the mail. `mpack -s "Hello" file.ext test@example.com` Further example, please visit [mpack(1) - Linux man page](https://linux.die.net/man/1/mpack)
Previous Post:
Docker
Loading