Last modified: Oct. 19, 2008
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 FreeBSD. Mail is a command line utility that sends
email using SMTP. This has been tested in FreeBSD 7.0.
2 - Sendmail configuration
Sendmail is included in FreeBSD by default. Edit /etc/rc.conf.local to have
the following options so they start on bootup. The sendmail submit process
allows posting messages. It can forward all outgoing messages to the mail
gateway specified in the SMART_HOST option. The sendmail msp_queue process
scans periodically the messages in the queue and make sure they don't get
stuck there.
sendmail_enable="NO"
sendmail_submit_enable="YES"
sendmail_submit_flags="-L sm-mta -bd -q30m"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="YES"
# sudo vi /etc/rc.conf.local
Get the hostname of the computer.
# hostname
server.test.com
Do the following to create an initial configuration file.
# sudo mkdir -p /root/backups/originals
# sudo cp -Rp /etc/mail/ /root/backups/originals/mail/
# cd /etc/mail
# sudo make
After this you should have some files that are named server.test.com. Make the
following changes to server.test.com.mc.
FEATURE(masquerade_envelope)
FEATURE(genericstable, `hash -o /etc/mail/genericstable')
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')
define(`SMART_HOST', `mail.test.com')
define(`confCW_FILE', `-o /etc/mail/local-host-names')
dnl DAEMON_OPTIONS(`Name=IPv6, Family=inet6, Modifiers=O')
# sudo vi server.test.com.mc
Create the following file so that you can rewrite your (envelope) From:
address for your host.
server.test.com
# sudo vi generics-domains
Create the following 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 vi genericstable
Create the following file so that the computer can deliver email to local users.
server.test.com
server
# sudo vi local-host-names
Rebuild the configuration files.
# sudo make all install stop
# sudo ps aux | grep sendmail
Edit server.test.com.cf to have the following to have sendmail not listen on
tcp port 587.
#O DaemonPortOptions=Port=587, Name=MSA, M=E
# sudo vi server.test.com.cf
Start the sendmail service.
# sudo make all install start
# sudo cat /var/run/sendmail.pid
2496
/usr/sbin/sendmail -L sm-mta -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"
recipient="testuser@test.com"
subject="Subject"
body="Body"
$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 FreeBSD.
# sudo shutdown -r now
# sudo ls -1 /var/run/sendmail.pid
/var/run/sendmail.pid
# sudo cat /var/run/sendmail.pid
638
/usr/sbin/sendmail -L sm-mta -bd -q30m
|