The simplest and most common type of e-mail configuration you can build is a single DNS domain with an Internet connection and a system that acts as a combined mail hub and a gateway. To support this simple configuration, you need only two different sendmail configuration files.
One configuration file is used on a single server that acts as both a mail hub and a gateway to the Internet.
The second configuration file is used on all other hosts. These hosts are dumb clients that defer all decisions to the domain's mail hub and gateway.
For this example, the domain name is starlight.com, and the system that acts as the mail hub and gateway is named mailhost.starlight.com. All outgoing e-mail is rewritten to appear as though it comes from [email protected], even if it is going from one local user to another, and all e-mail from the Internet will be addressed to [email protected].
Begin by first creating a /usr/lib/mail/client.mc client macro configuration file with the following contents.
dnl dnl client.mc: dnl Client macro configuration file for starlight.com dnl include(`/usr/lib/mail/m4/cf.m4') OSTYPE(`solaris2') FEATURE(`nullclient',`mailhost.starlight.com')
Notice that only one feature, nullclient, is activated. This feature tells all clients to send all e-mail generated locally to mailhost.starlight.com without doing any header rewriting.
Next, create the client sendmail configuration file from the /usr/lib/mail/client.mc file with the following command.
# m4 /usr/lib/mail/client.mc > /usr/lib/mail/client.cf
#
Finally, copy the resulting client.cf configuration file to /etc/mail/sendmail.cf on all of the client workstations.
The following example shows the /usr/lib/mail/hub-gateway.mc macro configuration file for the system that acts as the mail hub and gateway.
dnl dnl hub-gateway.mc dnl Mail Hub/Gateway macro configuration file for starlight.com dnl include(`/usr/lib/mail/m4/cf.m4')dnl OSTYPE(`solaris2')dnl dnl dnl Now make everything look like it comes from [email protected] dnl MASQUERADE_AS(`starlight.com')dnl dnl dnl Masquerade header recipients too dnl FEATURE(allmasquerade)dnl dnl dnl And the envelope as well dnl FEATURE(masquerade_envelope)dnl dnl dnl Activate DNS-based black hole, to drop mail from known spammer sites dnl Activate Realtime black hole, to drop mail from known spammer sites dnl When upgrading to sendmail 8.10, change this to the `dnsbl' feature dnl FEATURE(rbl)dnl dnl dnl Turn on mailertable feature so that we can relay to certain domains dnl by using gateways WE define in the /etc/mailertable file. (in 8.10, this dnl file will move to /etc/mail/mailertable, so we're putting it there dnl manually for now) dnl FEATURE(use_cw_file)dnl FEATURE(`mailertable',`hash -o /etc/mail/mailertable')dnl FEATURE(`domaintable',`hash -o /etc/mail/domaintable')dnl FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable')dnl FEATURE(`access_db',`hash -o /etc/mail/access')dnl dnl dnl Allow relaying of hosts in the starlight.com domain, but also dnl allow us to specify more domains that we will relay in dnl /etc/mail/relay-domains dnl FEATURE(relay_entire_domain)dnl RELAY_DOMAIN_FILE('-o /etc/mail/relay-domains')dnl dnl dnl Configurable options are modified here dnl define(`confSMTP_LOGIN_MSG',`[$j Sendmail $v/$Z; $b, starlight.com]')dnl define(`confCW_FILE',`-o /etc/mail/sendmail.cw')dnl dnl dnl define MAILERs here dnl MAILER(`local') MAILER(`smtp')
Let's break down the components of this file.
The first section contains comments and the regular heading for macro configuration files.
dnl dnl hub-relay.mc dnl Mail Hub/Gateway macro configuration file for starlight.com dnl include(`/usr/lib/mail/m4/cf.m4')dnl OSTYPE(`solaris2')dnl
The masquerading section comes next. The first MASQUERADE_AS directive makes all e-mail look as though it comes from [email protected] instead of from username or [email protected]. Without this directive, the DNS MX records (discussed later) won't work properly. The allmasquerade feature also rewrites recipients that are in the starlight.com domain, converting them from username to [email protected]. The masquerade_envelope feature rewrites the enclosing envelope of all messages.
dnl dnl Now make everything look like it comes from [email protected] dnl MASQUERADE_AS(`starlight.com')dnl dnl dnl Masquerade header recipients too dnl FEATURE(allmasquerade)dnl dnl dnl And the envelope as well dnl FEATURE(masquerade_envelope)dnl Next we activate a SPAM reduction feature: dnl dnl Activate DNS-based black hole, to drop mail from known spammer sites dnl Activate Realtime black hole, to drop mail from known spammer sites dnl When upgrading to sendmail 8.10, change this to the `dnsbl' feature dnl FEATURE(rbl)dnl
The next section activates several external configuration files that change how sendmail carries out certain activities and decisions. The first line activates the use of the /etc/sendmail.cw file (but, later in this file we change the location to /etc/mail/sendmail.cw). Then, we activate the mailertable, domaintable, virtusertable, and access_db features.
NOTE
These features are all hash maps that you create with the makemap command. However, you make all these maps optional with the -o option. sendmail now recognizes the maps if they exist and ignores them if they do not exist.
dnl dnl Turn on mailertable feature so that we can relay to certain domains dnl by using gateways WE define in the /etc/mailertable file. (in 8.10, this dnl file will move to /etc/mail/mailertable, so we're putting it there dnl manually for now) dnl FEATURE(use_cw_file)dnl FEATURE(`mailertable',`hash -o /etc/mail/mailertable')dnl FEATURE(`domaintable',`hash -o /etc/mail/domaintable')dnl FEATURE(`virtusertable',`hash -o /etc/mail/virtusertable')dnl FEATURE(`access_db',`hash -o /etc/mail/access')dnl
The next section defines the relaying policy. For this domain, we relay e-mail sent from any system in the starlight.com domain. For the future, we also allow the file /etc/mail/relay-domains to list any other domains for which we will relay.
NOTE
The /etc/mail/relay-domains file is a text file and you do not need to process it with the makemap command. The -o option specifies that the file is optional.
dnl dnl Allow relaying of hosts in the starlight.com domain, but also dnl allow us to specify more domains that we will relay in dnl /etc/mail/relay-domains dnl FEATURE(relay_entire_domain)dnl RELAY_DOMAIN_FILE('-o /etc/mail/relay-domains')dnl
You make any changes to the sendmail default options in the next section. Here, we simply customize the SMTP login message to include the starlight.com domain name and change the default location of the sendmail.cw file from /etc/sendmail.cw to /etc/mail/sendmail.cw.
dnl dnl Configurable options are modified here dnl define(`confSMTP_LOGIN_MSG',`[$j Sendmail $v/$Z; $b, starlight.com]')dnl define(`confCW_FILE',`-o /etc/mail/sendmail.cw')dnl
The final section includes the mailers we want to activate. In this case, the mail hub needs to be able to deliver mail locally to the mail spool and to transfer e-mail via the SMTP mailer.
dnl dnl define MAILERs here dnl MAILER(`local') MAILER(`smtp')
When you have finished creating the hub-gateway.mc file, you use it to generate the sendmail configuration file with the following command.
# m4 /usr/lib/mail/hub-gateway.mc > /usr/lib/mail/hub-gateway.cf
#
Then, copy the resulting hub-gateway.cf file to /etc/mail/sendmail.cf on mailhost.starlight.com.
Before you can start sendmail on mailhost.starlight.com, you must minimally configure some of the external databases. These databases and their contents are listed below.
Because this system is the mail hub, use this file to ensure that all incoming e-mail for [email protected] is ultimately delivered on this system. This file also deals with the unlikely event that e-mail may arrive addressed to [email protected].
# # Locally handle anything ending with starlight.com on this system. # Also, locally handle any e-mail addressed to # [email protected] in case such a format is used. starlight.com local: .starlight.com local:
Use the makemap command to process this file into a hash map, as shown below.
# makemap hash /etc/mail/mailertable > /etc/mail/mailertable
#
Use this file to ensure that e-mail originating from within your domain is accepted for delivery by this gateway to any location anywhere. The relay-domains file must contain your domain name.
# List domains for which we actually relay mail. # If a domain is not listed here, relaying of mail from that domain is denied. starlight.com
Because sendmail treats relay-domains as a plain text file, you need take no other action to process it.
Use this file to list all of the names by which this host is known so that sendmail recognizes that e-mail sent to any of those host names is truly intended for this system. Also, list the domain name here because most e-mail is sent to [email protected], and you want sendmail to recognize that starlight.com is another way of referring to this host.
# List all the names by which the mail hub is known so that sendmail # doesn't get confused into thinking that it shouldn't # deliver mail into the proper spool on this system. Note # that you list the DNS domain itself at the end of the list because # most e-mail will be addressed to [email protected] mailhost.starlight.com starlight.com
Because sendmail treats sendmail.cw as a plain text file, you need take no other action to process it.
Now that you have customized all of these files, restart sendmail so that it reads the files and uses their settings to make decisions for incoming and outgoing e-mail.
To ensure that all e-mail sent from any Internet site directly reaches the system acting as the starlight.com e-mail gateway and hub, put entries like those shown in the following example in the starlight.com DNS server tables.
starlight.com IN MX 10 mailhost mailhost IN A 205.172.3.45
This example assumes that the IP address of the system that acts as the mail hub and gateway is 205.172.3.45. Any Internet site trying to send e-mail to [email protected] performs a DNS lookup and discovers that the mail exchanger (MX) record for all e-mail destined for starlight.com should be sent directly to mailhost.starlight.com, with a preference of 10.
18.191.239.48