Last modified: Apr. 1, 2009
Contents
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/server.test.com.cf -bd -q30m"
# sudo vi /etc/rc.conf.local
Get the hostname of the computer.
# hostname
server.test.com
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 openbsd-proto.mc server.test.com.mc
# sudo chmod u+w server.test.com.mc
After this you will have a configuration file named server.test.com. Make the
following changes to server.test.com.mc.
define(`SMART_HOST', `mail.test.com')dnl
define(`confCW_FILE', `-o MAIL_SETTINGS_DIR`'local-host-names')dnl
FEATURE(genericstable, `hash -o /etc/mail/genericstable')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
dnl DAEMON_OPTIONS(`Family=inet6, Address=::, Name=MTA6, M=O')dnl
dnl DAEMON_OPTIONS(`Family=inet, Address=0.0.0.0, 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
FEATURE(masquerade_envelope)dnl
# sudo vi server.test.com.mc
Create the generics-domains file with the following so that you can rewrite
your (envelope) From: address for your host.
server.test.com
# 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.
root noreply@test.com
# sudo vipw
# sudo vi genericstable
Add the following to the local-host-names file so that the computer can
deliver email to local users.
server.test.com
server
# sudo vi local-host-names
Rehash the files.
# sudo make
Rebuild the configuration file.
# cd /usr/share/sendmail/cf
# sudo m4 ../m4/cf.m4 server.test.com.mc > /etc/mail/server.test.com.cf
Stop the sendmail service and then start it up again.
# sudo kill -9 `head -n 1 /var/run/sendmail.pid`
# sudo rm -fP /var/run/sendmail.pid
# sudo ps aux | grep sendmail
# sudo sendmail -L sm-mta -C/etc/mail/server.test.com.cf -bd -q30m
# sudo cat /var/run/sendmail.pid
26865
sendmail -L sm-mta -C/etc/mail/server.test.com.cf -bd -q30m
3 - Example shell script
Here is an example shell script that sends an email.
#!/bin/sh
clear=/usr/bin/clear
echo=/bin/echo
mail=/usr/bin/mail
hostname=/bin/hostname
host=`$hostname`
date=/bin/date
current_time=`$date +%H:%M`
current_day=`$date +%m/%d/%Y`
recipient="testuser@test.com"
subject="Test sent from $host"
body="This is a test. It was sent at $current_time on $current_day."
$clear
$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/sendmail.pid
/var/run/sendmail.pid
# sudo cat /var/run/sendmail.pid
12318
/usr/sbin/sendmail -L sm-mta -C/etc/mail/server.test.com.cf -bd -q30m
|