Table of Contents
This updated guide examines Com: How to Configure Sendmail and organizes the essential facts, background, and practical takeaways in clear American English.
Method 1
Download Sendmail
- Download Sendmail[1]. You may be automatically offered a short initial message which will indicate the current release. These instructions below assume version 8.10.0 or later.
- Build and install Sendmail for your machine. In most cases, this consists of unpacking the distribution, reading the README and sendmail/README files, and typing Build in the Sendmail directory. See the INSTALL file in the distribution's top-level directory for details.
Method 2
Set up Sendmail
- Understand that Sendmail uses information from the Domain Name System (DNS) to figure out which IP addresses go with which mailboxes.
- Choose an available domain name. In our example, we will use yourdomain.com .
- Configure your DNS on the server. Establish two machines as primary and secondary name servers for your domain. Knowledge of how to do this is assumed; otherwise, read the O'Reilly book "DNS and BIND", 4th Edition is highly recommended. Familiarize yourself with BIND before continuing.
- Configure MX records for your domain (Note: CNAME records cannot be used; see § 5.2.2 of RFC 1123 for details.) MX records are explained in the O'Reilly Sendmail book; the 2nd edition gives an overview in § 15.3 and describes how to configure them in § 21.3, whereas the third edition explains everything about them in § 9.3. You have two options for MX records:
- Determine your connection method:
- If the mail server which will serve your new domain has a full-time connection to the Internet, it should be the primary MX host for your domain. In this configuration, your MX records would look like this:
- yourdomain.com. IN MX 10 yourmailserver.yourdomain.com.
- Otherwise, you will need to find another machine to queue mail for your domain when you are not connected. Be sure to get the machine owners' approval first. That machine must be configured to allow relaying to your domain. If it is running Sendmail, this can be as simple as adding your domain to therelay-domainsfile on that machine. You would then point your MX records at that machine. For example:
- yourdomain.com. IN MX 10 yourmailserver.yourdomain.com.
- yourdomain.com. IN MX 20 othermailserver.otherdomain.com.
- If the mail server which will serve your new domain has a full-time connection to the Internet, it should be the primary MX host for your domain. In this configuration, your MX records would look like this:
- Now the name servers are setup, register your domain using one of the registries. As you register, inform the registry of the two name servers, and then the domain will point to your server.
Method 3
Configure Sendmail
- Read thecf/READMEfile thoroughly. It will give you instructions on creating a.mcfile in thecf/cfdirectory. Yourmailserver.mcfile will typically look something like:
- divert(-1)dnl
- #
- # This file contains the global definitions for yourdomain.com
- #
- divert(0)dnl
- VERSIONID(`@(#)mailserver.mc 1.0 (yourdomain.com) 5/1/97')
- OSTYPE(solaris2)dnl
- DOMAIN(yourdomain.com)dnl
- FEATURE(`virtusertable', `dbm /etc/mail/virtusertable')dnl
- MAILER(local)dnl
- MAILER(smtp)dnl
- Your actual OS will be substituted for solaris2.
- A typicalcf/domain/yourdomain.com.m4file that looks something like:
- divert(-1)dnl
- #
- # This file contains the global definitions for yourdomain.com
- #
- divert(0)dnl
- VERSIONID(`@(#)yourdomain.com.m4 1.0 (yourdomain.com) 5/1/97')
- FEATURE(`use_cw_file')dnl
- It may have some otherfeature()'s anddefine()'s as well. The virtual user table is the key to all of this.
- Generate your/etc/mail/sendmail.cffile from yourmailserver.mcfile, so type:
- cd sendmail-VERSION/cf/cf
- /Build mailserver.cf
- cp mailserver.cf /etc/mail/sendmail.cf
- Create the virtual user table. This is explained in detail in the Sendmail book: § 19.6.28 of the 2nd edition, or § 4.8.51 of the 3rd edition; an overview is given here. The table is a database that maps virtual addresses into real addresses. You create a text file where each line has a key/value pair, separated by a TAB. For example:
- Example 1:
- joe@yourdomain.com jschmoe
- jane@yourdomain.com jdoe@othercompany.com
- @yourdomain.com jschmoe
- In this first example, the addressjoe@yourdomain.comwill be mapped to the local userjschmoe;jane@yourdomain.comwill be mapped to the remote userjdoe@othercompany.com, and anything else coming in toyourdomain.comwill also go tojschmoe.
- Example 2:
- joe@yourdomain.com jschmoe%3
- bogus@yourdomain.com &npsp; error:nouser No such user here
- list@yourdomain.com yourdomain-list
- @yourdomain.com %1@othercompany.com
- In this second example, the addressjoe@yourdomain.comwill be mapped to the local userjschmoe%3(see note 3 below for an explanation of what the %3 means), the addressbogus@yourdomain.comwill return the indicated error, the addresslist@yourdomain.comwill be mapped to the local useryourdomain-list(which you would use the aliases file to ultimately resolve) and every other user atyourdomain.comwill be mapped to a remote user of the same name atothercompany.com.
- Example 1:
- If you have a local user, say sam, and there is no key for sam@yourdomain.com and no catch-all key for @yourdomain.com, thenSendmailwill fall back to the local usersamwhen resolvingsam@yourdomain.com. To prevent this, you must use either a catch-all key or an explicit key forsam@yourdomain.com; theerror:nouserexample above may be useful in this instance.
- If you want a virtual address to resolve to more than one real address, you need to do it indirectly. Have the virtual address resolve to a local alias, then have the local alias resolve to the desired set of addresses. For example, in the virtual user table:
- joe@yourdomain.com localjoe
- then in the aliases file:
- localjoe: joe@othercompany.com, jane@othercompany.com
- In the above example:
- joe@yourdomain.com jschmoe%3
- joe@yourdomain.com localjoe
- The%3is the preservation of the optional+detailpart of the original address. In general, +detail means that whenSendmailgets an address likeuser+detail@domain, then if domain is in class w (see step 7 below),sendmailchecks to see ifuser+detailcan be resolved, then falls back to just plain user if not. Thus all of:
- joe@yourdomain.com
- joe+foo@yourdomain.com
- joe+reallylongextrapart@yourdomain.com
-
- would all match the above entry, with%3preserving the+detailpart of nothing,+fooand+reallylongextrapartrespectively.
-
- Multiple domains are allowed, and virtual addresses in each domain are independent. So for example, you could have:
- joe@yourdomain1.com localjoe
- joe@yourdomain2.com joe@othercompany.com
- joe@yourdomain3.com localjoe
- joe@yourdomain4.com error:nouser No such user here
- For people administering multiple domains, it may be easier to keep each domain's list in a separate file, then write a short script to concatenate all such files together into a master virtual user table. But we're getting ahead of ourselves; that's the next step...
Method 4
Build theSendmailUser Table
- Build the virtual user table. If the above virtual user table text file is located atsourcefile, and you are using the DBM database type, then use the command:
- makemap dbm /etc/mail/virtusertable< sourcefile
- Note: if you builtSendmailwithNEWDBinstead ofNDBM, then use hash instead of dbm in the above line.
- This creates one or more non-text files (typically/etc/mail/virtusertable.dirand/etc/mail/virtusertable.pag, or/etc/mail/virtusertable.db), but does not actually change/etc/mail/virtusertableitself, so this is the recommended location forsourcefile.
- If you would like to reverse-map local users for out-bound mail, you will need to add support for the generics table to your.mcfile:
- FEATURE(`genericstable', `dbm /etc/mail/genericstable')dnl
- GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
- And you will need to create/etc/mail/genericstablewhich is like/etc/mail/virtusertableabove except the columns are reversed:
- jschmoe joe@yourdomain.com
Method 5
Add your domain names toSendmail
- Add each new domain name tosendmail's classw. This is typically done by adding a line to/etc/mail/local-host-names(known as/etc/sendmail.cwprior to version 8.10) with the value of each domain name. Likewise, if you are using thegenericstable, you should add any domains you wish to reverse-map to/etc/mail/generics-domains.
- Restart orSIGHUP sendmail.
- You do not need to restartsendmailwhen changing the virtual user or generics tables, only when changing/etc/mail/sendmail.cfor class files such as/etc/mail/local-host-names.
- An extra step is required for hosts not connected full-time. As noted in the MX configuration section, if you use another host to queue your mail until you connect, you will have to force delivery of mail queued on the secondary mail server. To accomplish this, when your primary server connects, you should run the scriptetrn.plwhich comes in thecontribdirectory of thesendmaildistribution:
- etrn.pl secondary-mx-host yourdomain.com
- It may be advisable to put this at the end of theSendmailstart-up script on any primaryMX. It would be especially useful as a follow-up to whatever script initiates the connection on primaryMXs without full-time connections.
- At this point, you should be set, and people should be able to send e-mail to addresses@yourdomain.com.
- An extra step is required for hosts not connected full-time. As noted in the MX configuration section, if you use another host to queue your mail until you connect, you will have to force delivery of mail queued on the secondary mail server. To accomplish this, when your primary server connects, you should run the scriptetrn.plwhich comes in thecontribdirectory of thesendmaildistribution:
Method 6
Test your configuration file
- Test your configuration and make sure everything works as expected before announcing the new domain name and mail addresses for that domain. If things don't work as expected, you can test withSendmail's test mode:
- sendmail -bt
- Here are some examples of things to try in test mode (make sure the domain is in class w:):
- $=w
- # is the map working?
- /map virtuser joe@yourdomain.com
- /map virtuser jane@yourdomain.com
- /map virtuser @yourdomain.com
- is the rewriting working? #**,0 joe@yourdomain.com #**,0 some@yourdomain.com
FAQ
What is Com: How to Configure Sendmail about?
It provides a structured overview of com, explains the main context, and highlights practical takeaways for readers.
Why does this topic matter?
Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.
How should readers use this information?
Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.
Reader Comments 0
Sign in with email or Google to join the discussion.