Sendmail

10:41 PM

Installing 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
yum install sendmail-cf
  • Installing using rpm

rpm --Uhv sendmail*
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
Lines that begin with dnl (delete to new line) are comment lines.
  • 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
Though you see them commented above, 9 is the default logging level by default. You may find uncommented "O LogLevel=9" in sendmail.cf instead. Logs are written to /var/log/maillog by default as defined in /etc/syslog.conf
  •  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.
NOTE:  Valid entries for SMART_HOST is a FQDN like 'relay.customer.com' or IPs. Because the sendmail Docs don't make this clear, if you are trying to add an IP as a SMART_HOST it must be enclosed in '[]' (square brackets). So if you are trying to setup a relay for customer and don't want to create an FQDN to a private internal IP with an /etc/hosts entry, then an IP is valid if and only if you configure it like - define(`SMART_HOST', `[10.xxx.xxx.xxx]')
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
Wondering why root user can't be masqueraded, well you have to remove/comment following line and rebuild the sendmail configuration if you do not wish root to be exposed.
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
This completes a basic overview of sendmail.mc file
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
Basically, there are 4 actions that you have the server take on a match:
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
After adding the required entries in virtusertable (use any text editor such as vi to edit /etc/mail/virtusertable), it must be rebuilded (or restart sendmail):
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
In the above example, there are lot of administrative users (bin, daemon, adm, lp etc.) instead of having separate mailboxes for each, they are redirected to root's mail box.  You can also use this file to create a mini mailing list, the above example has an entry for family which is forwarded to 3 addresses. Mails can also sent to be file as well, in the above example there is an entry for trouble-ticket which  stores incoming tickets in file /var/spool/trouble/incoming.
If you edit this file, use the following command to rebuild aliases (or restart sendmail)
# newaliases

You Might Also Like

0 comments

Contact Form

Name

Email *

Message *

Translate

Wikipedia

Search results