Setting up Sendmail for a home mail server
Thursday, September 20th 2012 in
FreeBSD comes pre-installed with
sendmail. This is an old program which sends and receives emails. Configuring it for use as a home email server is quite simple.
The first thing that you need to do is make sure that it is enabled to start on boot. Edit
/etc/rc.conf and add the line
Next, we need to configure sendmail to send and receive email. This will require editing
/etc/mail/sendmail.cf. The first thing to do is to specify which domains we should accept email for. Add these to the end of the
Cwlocalhost line, e.g.
Cwlocalhost domain1.com mail.domain2.com
Incoming email reaching our server with a domain not included in this list will be relayed.
If this is a home server, the ISP most likely assigns your IP address dynamically. This can cause a problem, as many major email services do not accept mail from dynamic IP addresses. To get around this, many ISPs allow you to relay your mail through their mail servers, which are generally accepted by other mail servers. For example, if the SMTP server for you ISP is
smtp.isp.net, you will want to enter or modify the following line:
Make sure that there is not a space between
DS and the SMTP server name.
You should now be able to send mail and receive mail, for example using the command-line mail client
The next step is to prevent unauthorized mail relaying. We don’t want spammers to find out that we are open to relay any email, as spam from them, relayed through us, would be attributed to us. Modify the file
/etc/mail/access and add lines such as
This will allow relaying for any host in our local network 192.168.0.0/24, and also allow relaying for the host 220.127.116.11, for example your email client at work.
Once this is completed, we start or restart
# /etc/rc.d/sendmail start