Sendmail
10:41 PMInstalling and running sendmail
Sendmail distribution consists of 3 rpm packages:sendmail - Truly necessary to send and receive email
sendmail-cf -- Includes configuration macros and other files that can help reconfigure sendmail installation
sendmail-doc -- contains documentation file
Installing using yum
yum install sendmail-cf
Installing using rpm
Starting sendmail # /etc/init.d/sendmail start
Basic Sendmail Configuration
Most of sendmail's configuration parameters are defined in the /etc/mail/sendmail.mc file, which is then used by the m4 macros to create the /etc/mail/sendmail.cf file.
Configuration of the sendmail.mc file is much simpler than configuration of sendmail.cf, but still you may find little intimidating. Remember, few of opsource customers might directly edit sendmail.cf, so editing sendmail.mc and rebuilding the config may overwrite their settings. It is always advisable to take backup of both sendmail.mc and sendmail.cf depending upon what you edit.
Below we will cover some basic lines in sendmail.mc that are considered important or edited mostly by linux admins:
- The first few lines of sendmail.mc do some housekeeping. The divert line remove extra output when configuration file is generated. OSTYPE must be set to linux to get the proper location of files needed.
divert(- 1 )dnl include(`/usr/share/sendmail-cf/m4/cf.m4')dnl VERSIONID(`setup for linux')dnl OSTYPE(`linux')dnl |
- Below lines define logging level.
dnl # default logging level is 9 , you might want to set it higher to dnl # debug the configuration dnl # dnl define(`confLOG_LEVEL ', `9' )dnl |
- Below is the line for smarthost. Smart hosts are usually used when all other methods of delivery have failed. It would be perfectly reasonable to have the hosts attempt to deliver mail directly first (local server), and if that fails then to send it to the smart host.
dnl # Uncomment and edit the following line if your outgoing mail needs to dnl # be sent out through an external mail server: dnl # dnl define(`SMART_HOST ', `secondaryhost.ood.ops' )dnl |
- Below 3 lines set locations for programs that distribute incoming mail (procmail, by default), mail aliases file, mail statistics file.
define(`PROCMAIL_MAILER_PATH ', `/usr/bin/procmail' )dnl define(`ALIAS_FILE ', `/etc/aliases' )dnl define(`STATUS_FILE ', `/var/log/mail/statistics' )dnl |
- Below 2 lines are are related to how mail queue should be handled. By default, sendmail will send a warning email after four hours that email has been deferred. After 5 days, it sends a bounce back message that mail delivery to intended recipient permanently failed. Remember, sendmail retries every hour to keep on sending a failed message every hour until 5 days after which the message is permanently discarded.
define(`confTO_QUEUEWARN ', `4h' )dnl define(`confTO_QUEUERETURN ', `5d' )dnl |
- FEATURE macro is used to set sendmail special features. virtusertable options sets the location of virtusertable database.
FEATURE(`virtusertable ', `hash -o /etc/mail/virtusertable.db' )dnl |
- DAEMON_OPTIONS is commented below. Therefore incoming mail from internet is allowed as well.
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 # dnl DAEMON_OPTIONS(`Port=smtp,Addr= 127.0 . 0.1 , Name=MTA')dnl |
- If you want your mail to appear to come from user@opsource.net and not user@thishost.ood.ops or user@localhost, then you have to consider setting up masquerading (of course, there is an option in email clients to change the @ address). masquerade modifies the domain name of all traffic originating from and passing through your mail server except from root user. Below lines are self-explanatory.
dnl # The following example makes mail from this host and any additional dnl # specified domains appear to be sent from mydomain.com dnl # MASQUERADE_AS(`opsource.net')dnl dnl # dnl # masquerade not just the headers, but the envelope as well dnl # FEATURE(masquerade_envelope)dnl MASQUERADE_DOMAIN(localhost)dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl MASQUERADE_DOMAIN(thisserver.ood.ops)dnl |
EXPOSED_USER(`root')dnl |
- Procmail is mailer by default, below configuration defines cyrus-imap to be used as imap server.
MAILER(smtp)dnl dnl MAILER(procmail)dnl dnl define( 'confLOCAL_MAILER' , `cyrusv2')dnl MAILER(cyrusv2)dnl |
If you would need to edit sendmail.mc and rebuild the sendmail.cf, use m4 macro to regenerate the new configuration:
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf |
Defining Outgoing Mail Access
Every time an email message intended for outgoing mail is received by your sendmail server, the server needs to decide if it will accept or reject relaying of that message.Example entry for /etc/mail/access
# by default we allow relaying from localhost...
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:192.168 RELAY
From:chris@opsource.net RELAY
To:gmal.com DISCARD
To:spammer-domain.net REJECT
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:192.168 RELAY
From:chris@opsource.net RELAY
To:gmal.com DISCARD
To:spammer-domain.net REJECT
RELAY - It will simply send the message on to the mail server requested in the mail message.
REJECT - Message is rejected and sender is informed that it was rejected.
DISCARD - Message is silently discarded and sender is not informed.
ERROR - One can add some informative text here, customize and let the sender know why it was not relayed.
After any changes to /etc/mail/access, it must be rebuilded (or consider restarting sendmail)
Rebuilding /etc/mail/access
# makemap hash /etc/mail/access.db < /etc/mail/access |
Note: You can also use /etc/mail/relay-domains to set up relay. Use FQDN only in this file. One disadvantage of this file is that controls mail based on the source domain only, and source domains can be spoofed by spam e-mail servers. The /etc/mail/access file has more capabilities, such as restricting relaying by IP address or network range and is more commonly used. If you delete /etc/mail/relay-domains, then relay access is fully determined by the /etc/mail/access file.
Configuring Virtual Users
/etc/mail/virtusertable
The /etc/mail/virtusertable file contains a set of simple instructions on how to treat received email. The first column lists the target email address and the second column lists the local user's mail box, a remote email address, or a mailing list entry in the /etc/aliases file to which the email should be forwarded.If there is no match in the virtusertable file, sendmail checks for the full email address in the /etc/aliases file.
Example entry for /etc/mail/virtusertable
webmaster@opsource.net webmasters
@dimensiondata.com marc
sales@opsource.net sales@dimensiondata.com
paul@opsource.net paul
finance@opsource.net paul
@opsource.net error:nouser User unknown
@dimensiondata.com marc
sales@opsource.net sales@dimensiondata.com
paul@opsource.net paul
finance@opsource.net paul
@opsource.net error:nouser User unknown
Rebuilding virtuserable:
# makemap hash /etc/mail/virtusertable.db < /etc/mail/virtusertable |
/etc/aliases file
A more flexible method of handling mail delivery (sytem wide rather than being specific to one particular user) involves the /etc/aliases file. One 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.
# Basic system aliases -- these MUST be present.
mailer-daemon: postmaster
postmaster: root
# General redirections for pseudo accounts.
bin: root
daemon: root
adm: root
lp: root
# Mailing list (Mail sent to "family@opsource.net" goes to addresses described below)
family: brother@hotmail.com, sister@gmail.com, father@yahoo.com
# sending to a file
trouble-ticket: /var/spool/trouble/incoming
mailer-daemon: postmaster
postmaster: root
# General redirections for pseudo accounts.
bin: root
daemon: root
adm: root
lp: root
# Mailing list (Mail sent to "family@opsource.net" goes to addresses described below)
family: brother@hotmail.com, sister@gmail.com, father@yahoo.com
# sending to a file
trouble-ticket: /var/spool/trouble/incoming
If you edit this file, use the following command to rebuild aliases (or restart sendmail)
# newaliases
0 comments