Configuring email for system event notification in OpenBSD

Last modified: Apr. 1, 2009

1 - Summary
2 - Sendmail configuration
3 - Example shell script
4 - Service check

1 - Summary

This guide will show you how to configure email using the mail utility for
system event notication in OpenBSD. Mail is a command line utility that sends
email using SMTP. This has been tested in OpenBSD 4.3 and 4.4.

2 - Sendmail configuration

Sendmail is included in OpenBSD by default. Edit /etc/rc.conf.local to have
the following options so it will start on bootup.

  sendmail_flags="-L sm-mta -C/etc/mail/ -bd -q30m"

# sudo vi /etc/rc.conf.local

Get the hostname of the computer.
# hostname

Do the following to get a configuration file.
# sudo mkdir -p /storage/backups/originals
# sudo cp -Rp /etc/mail/ /storage/backups/originals/mail/
# cd /usr/share/sendmail/cf
# sudo cp
# sudo chmod u+w

After this you will have a configuration file named Make the
following changes to

  define(`SMART_HOST', `')dnl
  define(`confCW_FILE', `-o MAIL_SETTINGS_DIR`'local-host-names')dnl
  FEATURE(genericstable, `hash -o /etc/mail/genericstable')dnl
  dnl DAEMON_OPTIONS(`Family=inet6, Address=::, Name=MTA6, M=O')dnl
  dnl DAEMON_OPTIONS(`Family=inet, Address=, Port=587, Name=MSA, M=E')dnl
  dnl DAEMON_OPTIONS(`Family=inet6, Address=::, Port=587, Name=MSA6, M=O, M=E')dnl
  dnl CLIENT_OPTIONS(`Family=inet6, Address=::')dnl

# sudo vi

Create the generics-domains file with the following so that you can rewrite
your (envelope) From: address for your host.

# cd /etc/mail
# sudo vi generics-domains

Add the following to the genericstable file which contains the mapping between
your local email address and your external one. We will use the root user so
you might want to change the comment field in /etc/passwd appropriately.


# sudo vipw
# sudo vi genericstable

Add the following to the local-host-names file so that the computer can
deliver email to local users.

# sudo vi local-host-names

Rehash the files.
# sudo make

Rebuild the configuration file.
# cd /usr/share/sendmail/cf
# sudo m4 ../m4/cf.m4 > /etc/mail/

Stop the sendmail service and then start it up again.
# sudo kill -9 `head -n 1 /var/run/`
# sudo rm -fP /var/run/
# sudo ps aux | grep sendmail
# sudo sendmail -L sm-mta -C/etc/mail/ -bd -q30m
# sudo cat /var/run/
sendmail -L sm-mta -C/etc/mail/ -bd -q30m

3 - Example shell script

Here is an example shell script that sends an email.


current_time=`$date +%H:%M`
current_day=`$date +%m/%d/%Y`
subject="Test sent from $host"
body="This is a test. It was sent at $current_time on $current_day."

$echo $body | $mail -s "$subject" $recipient
exit 0

4 - Service check

Reboot your computer. Log in like normal and check to see that the sendmail
service is running. That's it, now you have configured email for system event
notification in OpenBSD.
# sudo shutdown -r now
# sudo ls -1 /var/run/
# sudo cat /var/run/
/usr/sbin/sendmail -L sm-mta -C/etc/mail/ -bd -q30m

Last modified: Thu Jan 1 00:00:00 1970 UTC
Packetwatch Research 2002-2024.