It is very important to have some control and to know what is happening on the server so that errors are quickly visible. FreeBSD itself has some scripts with periodic that perform many regular tasks to maintain, heal or inform the system. FreeBSD also wants to report on these tasks and does so via email. What we still have to define in any case is WHERE and HOW these e-mails are sent.
NEW: For the very impatient I have a console only section. There are only commands, no explanations.
Last update:
DMA - DragonFly Mail Agent is a good and above all very lean basis for sending emails via SMTP and is much easier to configure than Sendmail or Postfix. After adapting the package source, dma
is quickly installed with pkg install -y dma
. Then it's time for the configuration:
Sendmail is completely deactivated with sysrc sendmail_enable=‘NONE’
, then some adjustments are made to the messages and tasks that are to be executed regularly via periodic:
sysrc -f /etc/periodic.conf daily_clean_hoststat_enable="NO" # Sendmail messages that are no longer required
sysrc -f /etc/periodic.conf daily_status_mail_rejects_enable="NO" # Sendmail messages that are no longer required
sysrc -f /etc/periodic.conf daily_status_include_submit_mailq="NO" # Sendmail messages that are no longer required
sysrc -f /etc/periodic.conf daily_submit_queuerun="NO" # Sendmail messages that are no longer required
sysrc -f /etc/periodic.conf daily_scrub_zfs_enable="YES" # Check ZFS pools regularly
sysrc -f /etc/periodic.conf daily_trim_zfs_enable="YES" # Regularly ‘trim’ ZFS pools
sysrc -f /etc/periodic.conf daily_status_zfs_enable="YES" # ZFS status report on utilisation and health
The configuration of dma
is then adapted to the mail server used with ee /etc/dma/dma.conf
:
SMARTHOST MAILSERVER # E-Mail Server Address e.g. mail.bytecamp.net
PORT 587 # SMTP Port
AUTHPATH /etc/dma/auth.conf # Logindata for MAILSERVER
SECURETRANSFER # Encrypted transmission
STARTTLS # Encrypted connection
MASQUERADE FROM-EMAIL # Sender e-mail address e.g. hostname@domain.tld
The access data is stored in a separate file with ee /etc/dma/auth.conf
:
LOGIN|MAILSERVER:PASSWORD # z.B. syslog@domain.tld|mail.bytecamp.net:P522W0r7
Then use chmod 660 /etc/dma/auth.conf
and chown root:mail /etc/dma/auth.conf
to protect the file from prying eyes.
By default, periodic sends all e-mails to the user root
, for which we store an e-mail address here with ee /etc/aliases
:
root: TO-EMAIL # Destination e-mail address e.g. syslog@domain.tld
Finally, this can be tested with the following command:
echo Testmessage | mail -v -s Testsubject TO-EMAIL
pkg install -y dma
sysrc -f /etc/periodic.conf daily_clean_hoststat_enable="NO"
sysrc -f /etc/periodic.conf daily_status_mail_rejects_enable="NO"
sysrc -f /etc/periodic.conf daily_status_include_submit_mailq="NO"
sysrc -f /etc/periodic.conf daily_submit_queuerun="NO"
sysrc -f /etc/periodic.conf daily_scrub_zfs_enable="YES"
sysrc -f /etc/periodic.conf daily_trim_zfs_enable="YES"
sysrc -f /etc/periodic.conf daily_status_zfs_enable="YES"
ee /etc/dma/dma.conf
SMARTHOST MAILSERVER
PORT 587
AUTHPATH /etc/dma/auth.conf
SECURETRANSFER
STARTTLS
MASQUERADE FROM-EMAIL
ee /etc/dma/auth.conf
LOGIN|MAILSERVER:PASSWORD
chown root:mail /etc/dma/auth.conf
chmod 660 /etc/dma/auth.conf
ee /etc/aliases
root: TO-EMAIL
echo Testmessage | mail -v -s Testbetreff TO-EMAIL