Using sSMTP on Slackware 15.0
How to Install and Use ssmtp to Send Emails from the Linux Terminal
ssmtp is a simple utility that can be used to send emails from a Linux system to a specified email address. It is just an MTA (Mail Transfer Agent); it does not receive mail, expand aliases, or manage a queue. Instead, it forwards automated emails to an external email address. This can be useful for forwarding system alerts or other automated emails from your system to an external email address.
According to the SlackBuild comments:
sSMTP, replaces sendmail on workstations that should send their mail via the departmental mailhub from which they pick up their mail (via pop, imap, rsmtp, pop_fetch, NFS… or the like). This program accepts mail and sends it to the mailhub, optionally replacing the domain in the From: line with a different one.
Normally, when using ssmtp, you want to remove the OS’s MTA package(s), sendmail and/or postfix. In this case, ssmtp will be symlinked to /usr/sbin/sendmail, and software that sends mail shouldn’t have to be modified. If you keep sendmail/postfix installed, there’s no conflict, but any software that sends mail will have to be configured or modified to use /usr/sbin/ssmtp.
NOTE: After installing, you’ll want to edit “/etc/ssmtp/ssmtp.conf”. There’s a man page for it (man ssmtp.conf).
In this post, we’ll show you how to install and use ssmtp to send an email from the command-line interface.
Step 1: Install ssmtp
By default, the ssmtp package is not included in the default install of Slackware but you can install it by running the following command if you use sbotools:
# sboinstall ssmtp
Step 2: Configure ssmtp
Next, you’ll need to define your Gmail or other SMTP servers in the
ssmtp configuration file. You can do this by editing the
/etc/ssmtp/ssmtp.conf
file:
vim /etc/ssmtp/ssmtp.conf
Add the following lines:
UseSTARTTLS=YES
root=user@your-isp.com
mailhub=smtp-mail.your-isp.com:587
rewriteDomain=192.168.1.12
hostname=192.168.1.12
FromLineOverride=YES
AuthUser=user@your-isp.com
AuthPass=your-email-password
AuthMethod=LOGIN
Save and close the file when you’re finished. ssmtp is now configured to use your SMTP server address to send an email.
Also modify the revaliases file in the same directory. A reverse alias gives the From: address placed on a user’s outgoing messages and (optionally) the mailhub these messages will be sent through. Example:
root:jdoe@isp.com:mail.isp.com
Messages root sends will be identified as from jdoe@isp.com and sent through mail.isp.com.
$ cat /etc/ssmtp/revaliases
# 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.
user:user@your-isp.com:smtp.your-isp.com:587
Step 3: Send an Email with ssmtp
First, create a text file and write some content:
vim file.txt
Add the following lines:
Subject: This is Subject Line
Email content line 1
Email content line 2
Save and close the file, then send an email with attachment
file.txt
to the external address
user@your-isp.com
:
ssmtp -v user@your-isp.com < file.txt
If everything is fine, you should see output indicating that the email was sent successfully.
And that’s it! You’ve successfully installed and used ssmtp to send an email from the Linux terminal. This can be a useful tool for sending automated emails from your system to an external email address.