Wednesday, May 25, 2005

Configuring Sendmail for send-only on FreeBSD

One of the first things you'll want to do after a fresh install of FreeBSD is configure email so you get the daily run output and other various emails from the system. Assuming this system will not become a mail server itself, you can follow these steps to accomplish this.

Setting up Sendmail
First, in rc.conf, set sendmail_enable="NO". This configures sendmail for receive only.

Next copy the default file to `hostname`.mc (where `hostname` will output the real hostname of the machine).

cd /etc/mail
cp `hostname`.mc

Now open up `hostname`.mc in your text editor of choice, and go down to the following line.

dnl define(`SMART_HOST', `your.isp.mail.server')

Change that line to the following, replacing with the name of your or your ISP's mail server.

define(`SMART_HOST', `')

Save the changes to `hostname`.mc and exit your editor. Then run the following commands.

make install

make restart-mta

Redirecting root's email
Now open up your /etc/aliases file in your text editor, so you can define an email address to send root's emails. Go down to the following line.

# root: me@my.domain

Uncomment it, and change me@my.domain to your actual email address. For example, if your email address is you would make the line look like the following.


Then save your changes and exit your editor.

Last, run the command newaliases to rebuild your mail aliases file, and you're set.

Alternatively, if you can get away with only text email functionality, ssmtp in ports is an easy solution. If you run a web site that needs to send HTML emails, as one example, this won't suffice since it will send them out in plain text. The FreeBSD Handbook documents how to configure ssmtp.