sendmail is an electronic mail transport agent, routing messages over whatever networks are necessary. The advantage of sendmail is that allows for internetwork forwarding to deliver the message to the correct place. The disadvantage is that if setup incorrectly, it allows for spammers to use your domain to spam accounts if setup to accept unresolvable domains. (Fortunately, this option is not set by default in the current version of Fedora.)
You can define most of sendmail's configuration parameters in the /etc/mail/sendmail.mc file, which is then used by "m4" macros to create a /etc/mail/sendmail.cf file. Configuration of the sendmail.mc file is much simpler than configuration of sendmail.cf, but it is still often viewed as an intimidating task. Fortunately, in most cases you won't have to edit this file very often.
In most Linux configuration files, a # symbol is used at the beginning of a line convert it into a comment line or to deactivate any commands that may reside on that line. However, the sendmail.mc file doesn't use this character for commenting, but instead uses the string "dnl".
Configure Your Mail Server's Name In DNS
You first need to make sure that your mail server's name resolves in DNS correctly. For example, if your mail server's name is [server] and it you intend for it to mostly handle mail for the domain [domain].[name], then [server].[domain].[name] must correctly resolve to the IP address of one of the mail server's interfaces. You can test this using the host command:
[server].[domain].[name] has address [xxx.xxx.xxx.xxx]
The sendmail program expects DNS to be configured correctly on the DNS server. Your domain must point to the IP address of the mail server.
The program also expects the files used by the mail server's DNS client to be configured correctly. The first one is the /etc/resolv.conf file, in which there must be a domain directive that matches one of the domains the mail server is expected to handle mail for. Finally, sendmail expects a nameserver directive that points to the IP address of the DNS server the mail server should use to get its DNS information.
For example, if the mail server is handling mail for [domain.name] and the IP address of the DNS server is [xxx.xxx.xxx.xxx], there must be directives that look like this:
The /etc/hosts file also is used by DNS clients and also needs to be correctly configured. Here is a brief example of the first line you should expect to see in it:
All Linux systems have a virtual loopback interface that lives only in memory with an IP address of 127.0.0.1. As mail must be sent to a target IP address even when there is no NIC in the box, sendmail therefore uses the loopback address to send mail between users on the same Linux server. To become a mail server, and not a mail client, sendmail needs to be configured to listen for messages on NIC interfaces as well.
1. Determine which NICs sendmail is running on. You can see the interfaces on which sendmail is listening with the netstat command. Because sendmail listens on TCP port 25, you use netstat and grep for 25 to see a default configuration listening only on IP address 127.0.0.1 (loopback):
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
dnl # The following causes sendmail to only listen on the IPv4 loopback address
dnl # 127.0.0.1 and not on any other network devices. Remove the loopback
dnl # address restriction to accept email from the internet or intranet.
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
dnl # We strongly recommend not accepting unresolvable domains if you want to
dnl # protect yourself from spam. However, the laptop and users on computers
dnl # that do not have 24x7 DNS do need this.
In conjunction with this, make sure that you have have poked a hole in the firewall for TCP/IP Port Number 25. See the Firewall page for details on how to do this if you have not done it already.
3. Make sure that the SMART_HOST entry in sendmail.mc has been commented out. The mail server doesn't need a SMART_HOST entry in its sendmail.mc file. Comment this out with a dnl at the beginning, if necessary.
dnl # specified domains appear to be sent from mydomain.com
dnl # masquerade not just the headers, but the envelope as well
dnl # masquerade not just @mydomainalias.com, but @*.mydomainalias.com as well
5. Edit the /etc/mail/local-host-names file and add any aliases your machine may have:
When sendmail receives mail, it needs a way of determining whether it is responsible for the mail it receives. It uses the /etc/mail/local-host-names file to do this. This file has a list of host names and domains for which sendmail accepts responsibility. For example, if this mail server was to accept mail for the domain [server].[domain].[name] then the file would contain the mail server's fully qualified domain name and any aliases.
Generate the New Sendmail Configuration File /etc/mail/sendmail.cf
When mail passes through a sendmail server the mail routing information in its header is analyzed, and sometimes modified, according to the desires of the systems administrator. As previously mentioned, using a series of highly complicated regular expressions listed in the /etc/mail/sendmail.cf file, sendmail inspects this header and then acts accordingly.
In recognition of the complexity of the /etc/mail/sendmail.cf file, a much simpler file named /etc/mail/sendmail.mc was created, and it contains more understandable instructions for systems administrators to use (which is what we just edited). These are then interpreted by a number of macro routines to create the sendmail.cf file. After editing sendmail.mc, you must always run the macros and restart sendmail for the changes to take effect.
Once you finish editing the sendmail.mc file with the above changes, you can then execute the make command while in the /etc/mail directory to regenerate the new sendmail.cf file.
sudo make -C /etc/mail
Shutting down sendmail: [ OK ]
Starting sendmail: [ OK ]
Starting sm-client: [ OK ]
After checking the contents of the virtusertable, sendmail checks the aliases files to determine the ultimate recipient of mail. If there is no match in the virtusertable file, sendmail automatically checks /etc/aliases.
You can think of the /etc/aliases file as a mailing list file. The first column has the mailing list name (sometimes called a virtual mailbox), and the second column has the members of the mailing list separated by commas.
To start, sendmail searches the first column of the file for a match. If there is no match, then sendmail assumes the recipient is a regular user on the local server and deposits the mail in their mailbox. If it finds a match in the first column, sendmail notes the nickname entry in the second column. It then searches for the nickname again in the first column to see if the recipient isn't on yet another mailing list. If sendmail doesn't find a duplicate, it assumes the recipient is a regular user on the local server and deposits the mail in their mailbox. If the recipient is a mailing list, then sendmail goes through the process all over again to determine if any of the members is on yet another list, and when it is all finished, they all get a copy of the e-mail message.
Because aliases can be very useful, here is an example for your /etc/aliases file:
# Directors of my company
One important note about the /etc/aliases file: By default, your system uses sendmail to mail system messages to local user root. When sendmail sends e-mail to a local user, the mail has no To: in the e-mail header. If you then use a mail client with a spam mail filtering rule to reject mail with no To: in the header, such as Outlook Express or Evolution, you may find yourself dumping legitimate mail.
To get around this, try making root have an alias for a user with a fully qualified domain name, this forces sendmail to insert the correct fields in the header; for example:
root: [master user]@[domain].[name]