Skip to content

Instantly share code, notes, and snippets.

@jblachly
Created August 26, 2018 19:03
Show Gist options
  • Save jblachly/f470c001f4b07ed7d76a47a85a32ce64 to your computer and use it in GitHub Desktop.
Save jblachly/f470c001f4b07ed7d76a47a85a32ce64 to your computer and use it in GitHub Desktop.
FreeBSD periodic output to external email addresses with SSMTP

Based in part on: https://www.debarbora.com/freebsd-10-1-setup-ssmtp-for-outgoing-mail/

Disable sendmail

Edit /etc/rc.conf to add:

sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

Stop the sendmail service nicely

service sendmail stop

Install the ssmtp package (may update other packages)

root@cancer-1050740:~ # pkg install -y ssmtp
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
The following 1 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
        ssmtp: 2.64_3

Number of packages to be installed: 1

19 KiB to be downloaded.
[1/1] Fetching ssmtp-2.64_3.txz: 100%   19 KiB  19.7kB/s    00:01
Checking integrity... done (0 conflicting)
[1/1] Installing ssmtp-2.64_3...
===> Creating groups.
Creating group 'ssmtp' with gid '916'.
[1/1] Extracting ssmtp-2.64_3: 100%
Message from ssmtp-2.64_3:

sSMTP has been installed successfully.

To replace sendmail with ssmtp type "make replace" or change
your /etc/mail/mailer.conf to:

sendmail        /usr/local/sbin/ssmtp
send-mail       /usr/local/sbin/ssmtp
mailq           /usr/local/sbin/ssmtp
newaliases      /usr/local/sbin/ssmtp
hoststat        /usr/bin/true
purgestat       /usr/bin/true


However, before you can use the program, you should copy the files
"revaliases.sample" and "ssmtp.conf.sample" in /usr/local/etc/ssmtp
to "revaliases" and "ssmtp.conf" respectively and edit them to suit
your needs.

Set up ssmtp.conf

A sample configuration with comments is in /usr/local/etc/ssmtp/ssmtp.conf.sample.

Create a new /usr/local/etc/ssmtp/ssmtp.conf with the following contents:

root=postmaster

# The place where the mail goes. The actual machine name is required
# no MX records are consulted. Commonly mailhosts are named mail.domain.com
# The example will fit if you are in domain.com and your mailhub is so named.
mailhub=<SMTP host IP or hostname>:587
AuthUser=<userid for authentication>
AuthPass=<user credentials for authentication>
FromLineOverride=NO
Hostname=_HOSTNAME_ (or whatever)
RewriteDomain=<domain where the mail should appear to come from>
useTLS=YES <- may be required for some SMTP providers instead of useSTARTTLS
useSTARTTLS=YES <- Confirmed to work with Amazon Simple Email Service (SES)

Then change permissions:

chmod o-r ssmtp.conf

Set up reverse aliases

A sample configuration with comments is in /usr/local/etc/ssmtp/revaliases.sample.

Create a new /usr/local/etc/ssmtp/revaliases with the following contents:

root:[email protected]:SMTP.hostname.com:587

(or :25 if not using TLS)

And then change permissions:

chmod o-r revaliases

Change the root user's name

chpass

Replace Charlie & in the Full Name: field with whatever.

Reroute calls to sendmail with ssmtp

After this step, outgoing mail will be enabled.

Replace /etc/mail/mailer.conf (as suggested after package installation) with:

sendmail        /usr/local/sbin/ssmtp
send-mail       /usr/local/sbin/ssmtp
mailq           /usr/local/sbin/ssmtp
newaliases      /usr/local/sbin/ssmtp
hoststat        /usr/bin/true
purgestat       /usr/bin/true

Test from command line

mail -v -s "cmdline test" [email protected] (use . on empty line to end)

Edit periodic settings

Open /etc/defaults/periodic.conf and search for lines

Include double quotes, use commas between email adresses, and do not include local account names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment