Monday, August 22, 2011

BSD Mail/ SendMail 101

While working on HE's IPv6 certification, I gathered some useful experiences with setting up a basic mail server on FreeBSD so I thought it would be worthwhile to do a quick blog on this...
Overview
Firstly, the Mail User Agent (MUA) is what the user uses to compose emails. BSD Mail is the default MUA which comes with FreeBSD. Its syntax is as follows (for composing emails):
#mail
Subject:
[Mail Content]
. Remember to enter a “.” in a new line to end writing the email
EOT
Secondly, the Mail Transfer Agent (MTA) is what interacts with the rest of the internet i.e. the MTA is responsible for sending and receiving emails. Sendmail is the default FreeBSD's MTA.
I configured the following files (under /etc/mail) to have this setup working:
1. "virtualusertable" - the email address accepted and local user to forward the email to.
2. "access" - like an ACL for emails, it identifies the incoming/ outgoing email addresses permitted/ denied.
3. local-host-names - email domain accepted into local machine.
In /etc/rc.conf, I have also added "sendmail_enable=yes"; along with setting my NAT gateway to accept TCP 25.
For those interested in more details, FreeBSD Handbook has dedicated a page on Sendmail. According to this page, there are certain occasions when either a "make" or process restart is required for the configuration changes to take effect but in the interest of keeping this post simple I will not go into any details here.
That seems to be it, Sendmail was running fine and accepting emails:
home-unix6# /etc/rc.d/sendmail status
sendmail is running as pid 1170.
sendmail_clientmqueue is running as pid 1174.
On DNS
Also worth noting is when you send an email, the local MTA actually perform two DNS queries:
1. MX (Mail Exchange) query against the destination email domain - to resolve the mail server's hostname.
2. A (or AAAA) query against the MX response, to resolve the IP address of the receiving SMTP server.
P.S. As a test, I tried sending an email to my service provider, iiNet email account, using this machine. Interesting enough, I received an error message informing me the email I sent has been rejected due to the "poor reputation" of the MTA...at least I can be sure my setup is working (there is a Whirlpool forum on this from others with similar experiences).

No comments:

Post a Comment