Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 30

Chapter 16

Sendmail
E-mail Services

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Objectives

Install sendmail
Configure sendmail
Recognize sendmail related files
Demonstrate how to use m4 processing
system

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
sendmail

sendmail is one of the most powerful and


difficult to configure mail transfer agents (MTA)
sendmail is primarily concerned with the
transferring of mail between MTAs
Other programs has the same function:
qmail, postfix, exim, …

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Install and Configure

Packets for installation:


sendmail-cf-8.11.6-3.i386.rpm
sendmail-8.11.6-3.i386.rpm
sendmail-doc-8.11.6-3.i386.rpm
Configure files :
/etc/sendmail.cf (RH7.x)
/etc/mail/sendmail.cf (RH8.0, …)
/etc/aliases
/etc/mail/access, /etc/mail/local-host-names
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Aliases configuration file

Declares E-mail alias names to individuals or


groups (mailing list) - also known mailing list
file.
Syntax : alias_name: first name, second name,

Forward mail to other addresses for users
utilizing a .forward file in their home directory
The newaliases command should be
executed each this file is changed. This
command creates the alias database for
sendmail located at /etc/aliases.db
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
aliases Sample File
# Basic system aliases -- these MUST be present.
mailer-daemon: postmaster
postmaster: root
# General redirections for pseudo accounts.
bin: root
daemon: root
adm: root
# Some well-known aliases
webmaster: webadmin
operator: root
manager: beck
# Person who should get root's mail
root: marc
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
sendmail.cf configuration file

This file controls how sendmail works.


It has 7 main sections with a variable number
of subsections. Each section contains several
lines.
Each line in the file defines a configuration
command, which begins with a short one or two
letter command definition (C, O, D, M, …).
The comments beginning with #

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
sendmail.cf Main Sections

Local Info Information for local host


Options Environment options
Message Precedences Message precedence value
Trusted Users Users who are allowed to
modify their address
Format of Headers Headers inserted into E-mail
Rewriting Rules Comprises a number of rule sets to
define the rule to rewrite message into useful
Mailer Definitions Defines the programs that
deliver mail : smtp, esmtp, procmail, uucp, …

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Short Command Leters
C Defines classes of text
Ex: Cwlocalhost
D Defines macro
Ex: DnMAILER_DEAMON (my name for error
message)
M Defines mailers
Ex: Mprocmail, P=/usr/bin/procmail, F=DFMSPhnu9,

O Defines options
Ex: O MaxHopCount=17
R Defines rule sets to parse address(0, 3, …)
K Define database that contains text to search
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Local Info Section

This section contains:


hostname, relay names (if present), name of the
mail domain
safety parameters, configuration format

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Local Info Section

Example Database Command :


Kmailertable hash -o /etc/mail/mailertable.db
K Declares mailertable to be a database
mailertable Name of the database
hash Data format
/etc/mail/ Location of the mailer table database

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Local Info Section

Example Macro Command :


DMYAST_ASK
DnMAILER-DAEMON
D Define macro
M, n Macro names being assigned
(usually one letter)

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Local Info Section

 Example Class Command :


Cw localhost
C Define a class
w Assigned class variable
localhost Variable that localhost is
assigned

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Local Info Section

Example File Command :


Fw-o/etc/sendmail.cw %[^\#]
F Load from a file
w-o Class variable where it is loaded
/etc/sendmail.cw The file to load it from
(this one defines hosts from where we
receive mail)

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Options Options

Example Sendmail options :


# strip message body to 7 bits
O SevenBitInputs=False
# wait for alias file to rebuild
O AliasWait=10
# location of the alias file
O AliasFile=/etc/aliases
# min number free blocks on system
O MinFreeBlocks=100
# Location of help file
O HelpFile=/usr/lib/sendmail.hf
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Message Precedences Section

Example :
Pfirst-class=0
Pspecial-delivery=100
Plist=-30
Pbulk=-60
Pjunk=-100

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Mailer Specification Section

Example :
Mprocmail P=/usr/bin/procmail F=DFMS
P Full path name of delivery program
F Specifies certain flags that tell sendmail more
about the delivery agent. Each flag is a single
character.

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
The m4 Macro System

It’s the easiest, most efficient way to


reconfigure Sendmail
The basic idea is that it uses a number of
other files and one configuration file to put
together a sendmail.cf file
All source of m4 contains in sendmail-cf
directory.The basic configuration in sendmailcf/
cf.

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Configure by using m4

Some regularly using file contains in /etc/mail


Make any changes in /etc/mail/sendmail.mc
sendmail.mc sendmail.cf
LOCAL_DOMAIN(`example.org')
Cwexample.org
Compile new sendmail.cf
# m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
Restart sendmail server daemon(if
necessary)
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Useful Script

A useful script to restart sendmail after editing


configuration files
#!/bin/bash
cd /etc/mail
make
m4 ./sendmail.mc > /etc/sendmail.cf #7.3-
m4 ./sendmail.mc > /etc/sendmail.cf #8.0+
newaliasses
/etc/init.d/sendmail restart
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Debug for error messages

Sendmail puts all its status message in


/var/log/maillog file.
Run :
tail –f /var/log/maillog

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Mail Queued

When mail can not be sent immediately, it’s


placed in a queue
Use mailq command to see the messages
waiting to be processed
Output format of mailq command:
<Q-Id> <Size> <Q-Time> <Sender/Recipient>
<Reason why the message wasn’t sent successfully>

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

1) Choose the right machine for the job :


2) Install RedHat and sendmail packages
/var/spool/mqueue contains your outgoing mail
queue
/var/spool/mail contains your users mail spools
(mail waiting to be downloaded by your users)

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

3) DNS setup for Mail services


Here is mail server information:
IP address: 64.244.27.132
Domain name: mail.example.org
Thus the DNS file from example.org looks something like this:

IN MX 10 mail.example.org.
IN MX 100 mail-bak.example.org.

mail IN A 64.244.27.132
mail-bak IN A 64.244.27.133

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

4) Modify sendmail.mc
Change :
dnl DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1,
Name=MTA')
LOCAL_DOMAIN(`localhost.localdomain')dnl
to :
DAEMON_OPTIONS('Port=smtp,Addr=0.0.0.0,
Name=MTA')
LOCAL_DOMAIN(`mail.example.org')dnl
Remember to run :
m4 ./sendmail.mc > /etc/mail/sendmail.cf
SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

4) Modify /etc/mail/sendmail.cf
Change :
Cwlocalhost
O DaemonPortOptions=Port=smtp,Addr=127.0.0.1,
Name=MTA
to :
Cwmail.example.org
O DaemonPortOptions=Port=smtp,Addr=0.0.0.0,
Name=MTA

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

5) Modify /etc/mail/local-host-names
example.org
mail.example.org
6) Modify /etc/mail/access
example.org RELAY
mail.example.org RELAY

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

7) Now run make (you have to be in the


directory
/etc/mail) to update the access.db file. Then
stop and start Sendmail so that it sees the new
information in the file local-host-names. You
should be ready to send and receive mail!

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Steps to setup simple Mail Server

8) Setting up POP or basic IMAP services :


 Now that Email is collecting on your mail server, you
will need a way to let local users download the mail
being stored there. You'll need to install the "imap" :
# rpm -i imap-2001a-15.i386.rpm
 Edit /etc/xinetd.d/ipop3 and change the "disable" line
to read: disable = no
 Restart xinetd : # service xinetd restart

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102
Summary

Install sendmail
Configure sendmail
Recognize sendmail related files
Demonstrate how to use m4 processing
system

SAIGONLAB 83 Nguyễn
69-3 ThịThi
Nguyen Nhỏ,Nho,
P9, Q.Tân Bình, Tp.Tp.
P9, Q.TBinh, HCMHCM LPI 102

You might also like