sendmail

sendmail
sendmail
 Widely used
 But with intimidated complex configuration
 Other mailservers
 Exchange, qmail, smail, Postfix, Courier, etc.
 Why sendmail is complex?
 To make it SIMPLE for different programs and
mail addressing schemes to work together
• SMTP: over TCP/IP
• UUCP(Unix to Unix Copy Protocol): over serial line
• Local mail deliver: sends mail between users on the
same system.
Sendmail
10-1
Sendmail
10-2
Sendmail’s Function
Routing between user programs and delivery programs
based on email address.
Receives
and delivers SMTP (Internet) mail
Provides
system wide mail aliases, which allow mailing
lists.
1
Sendmail daemon: Receive SMTP mail
 Listens to port 25 to process incoming mail.
 Started during system startup,
 Linux: /etc/rc.d/init.d/sendmail
• Arguments: start, stop, restart, condrestart, status
• Command line options: /etc/sysconfig/sendmail
DAEMON=yes # that is -bd
QUEUE=1h
# that is –q1h

Solaris: /etc/init.d/sendmail
• Arguments: start, stop
 otherwise manually start it by using the command:
# /use/lib/sendmail –bd –q15m
Sendmail
10-3
Sendmail Aliases
 Mail aliases provide
 Alternate names for individual users
 Forwarding of mail to other hosts
 Mailing lists
 Alias file
 line format:
alias: recipient[, recipient, …]
• alias is the name to which the mail is addressed
• recipient is the name to which the mail is delivered
– Username
– Another aliases
– Full email address containing both a username and hostname
• Multiple recipients created a mailing list
Sendmail
10-4
2
Aliases
 Alias file (Cont)
 Default location
• Solaris: /etc/mail/aliases
• Linux: /etc/aliases

Let’s take a look at cslserver.csl.mtu.edu’s aliases file
root: root@cec.mtu.edu
csreq: |"/export/csl/req/etc/req-mailgate"
systems-dist: jdpoisso,ruihong,lesong
 Rebuild aliases database
 Run the command newaliases
 Or start sendmail with –bi option
Sendmail
10-5
Personal Mail Forwarding
 ~/.forward
 Sendmail checks for .forward after using
the aliases file before the final delivery
 Individual user controls
 Easier
Sendmail
10-6
3
The sendmail.cf file
 Other than aliases, .forward, everything
else is in /etc/mail/sendmail.cf
Defines the sendmail env
 Rewrite addresses into appropriate syntax for
the receiving mailer
 Maps address into the instructions necessary to
deliver the mail

 Using m4 to build sendmail.cf
Sendmail
10-7
Using m4 to build sendmail.cf
 Sample mc
 Linux.mc
VERSIONID(‘……..’)
OSTYPE(‘…’)
DOMAIN(‘wrotethebook.com’)
FEATURE(‘nouucp’,’reject’)
MAILER(‘local’)
MAILER(‘smtp’)

Domain/wrotethebook.com.m4
MASQUERADE_AS(wrotethebook.com)
FEATURE(masquerade_envelope)
FEATURE(genericstable)

Makemap hash genericstable < realnames

#m4 cf.m4 linux.mc > sendmail.cf
Sendmail
10-8
4
Highlights about sendmail.cf
 Files used in sendmail.cf
[ruihong@cslserver ~]$ grep =/ /etc/mail/sendmail.cf
#O ErrorHeader=/etc/sendmail.oE
O HelpFile=/etc/mail/sendmail.hf
O QueueDirectory=/var/spool/mqueue
O StatusFile=/etc/mail/sendmail.st
#O UserDatabaseSpec=/etc/userdb
#O ServiceSwitchFile=/etc/service.switch
#O HostsFile=/etc/hosts
#O SafeFileEnvironment=/arch
Mlocal,
P=/opt/procmail/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=10/30, R=20/40,
Mprog,
P=/bin/sh, F=lsDFMoqeu9, S=10/30, R=20/40, D=$z:/,
Sendmail
10-9
Sendmail’s role in Queue management
O QueueDirectory=/var/spool/mqueue
 A mail message can be temporary undeliverable for
reasons: remote machine is down, disk problem, …
 To ensure the a message is eventually delivered,
sendmail stores the mail in a queue directory until
the message can be delivered successfully.


Queue is empty
Or a pair of files for each undelivered mail:
• header info
• Message

Use “sendmail –bp” to check the queue.
 Do not need to process queue too often.
 -q1h, -q15m for sendmail daemon as command line options
Sendmail
10-10
5
Sendmail’s role in Local Delivery
 Sendmail deliver mail message.
 By Appending a message to a file
 By feeding the mail message to a program.
• In alias file:
csreq: |"/export/csl/req/etc/req-mailgate“
• The | tells sendmail that this is a program to run rather
than a file to append to.
 Mailbox under unix
 A single file that contains a series of mail messages
Sendmail
10-11
Sendmail’s role in Local Delivery
 In General, sendmail calls other programs
to perform delivery
Mlocal,
P=/opt/procmail/bin/procmail, F=lsDFMAw5:/|@qSPfhn9, S=10/30, R=20/40, …
Mlocal: defines how mail is appended to a user’s mailbox file.
/usr/lib/mail.local
/bin/mail
procmail
deliver
Sendmail
10-12
6
Sendmail’s role in Network Transport
 Transporting mail to other machines.
 A message is transported when sendmail determines that
the recipient is not local.
 Defined delivery agents in the sendmail.cf
ruihong@cslserver mail]$ grep Msmtp sendmail.cf
Msmtp,
P=[IPC], F=mDFMuX, S=11/31, R=21/31, E=\r\n, L=990, …
Msmtp8,
P=[IPC], F=mDFMuX8, S=11/31, R=21/31, E=\r\n, L=990, …

Use other protocols
• Use Mmac line and /usr/bin/macmail to transport mail to
Macintosh machines that are connected on an AppleTalk
network.
• Use Mfax line and /usr/local/bin/faxmail to send a fax
using sendmail – a mail message is fed to faxmail for
conversion to and transmission as a fax image.
Sendmail
10-13
Sendmail’s role in Network Transport
 SMTP function over TCP/IP is internal to sendmail
 To send a mail
• Send recipient address to remote site first
• If remote site accepted the address, sendmail then send
the message (header and body together).

To receive a mail
• Start sendmail as a daemon with –bd option.
Sendmail
10-14
7
How to run sendmail besides daemon mode
 With the names of recipients
%/usr/lib/sendmail george
%/usr/lib/sendmail george,truman,teddy
 With other switches started with –
 -b set operating mode
Couple of example:
• -bd Run as a daemon
• -bi
Rebuild alias database
• -bt
Test mode:resolve addresses only
– Very useful for testing address transform rule set.
• -bp print the queue
• -bv Verify: don’t collect or deliver
– Very helpful, recursively lookup an alias and report the ultimate
real name that it found.


-v run in verbose mode
-d run in debugging mode
Sendmail
10-15
How to run sendmail besides daemon mode
 Other names: links to sendmail
 mailq
 newaliases
 purgestat
 smtpd
 Try some commands on
cslserver.csl.mtu.edu
1. sendmail –bv systems-dist
2. sendmail –bv root
Sendmail
10-16
8
How to run sendmail besides daemon mode
 Try some commands on cslserver.csl.mtu.edu (cont)
3. sendmail –v your-mail-address <<END
This is a test email
END
Notes: lines begin with numbers and >>> constitute a
record of the SMTP conversation.
Lines with numbers: reply from remote
Lines with >>>: local machine sends to remote
4. /usr/lib/sendmail –d yourself < /dev/null
Sendmail
10-17
Building a sendmail.cf
 General structure
 Local information
• Hostname
• Mail relay host
• Mail domain






Options
Message Precedence
Trusted Users
Format of Headers
Rewriting Rules
Mailer Definitions
 Very little of sendmail.cf needs to be modified for
a typical system.
Sendmail
10-18
9
Sendmail.cf configuration
language
 Easy to parse for sendmail, not for humans
 No space between variable and value.
 Long variable is allowed within braces
D{Domain}wrotethebook.com
Sendmail
10-19
Table: sendmail Configuration Commands
Command
Version Level
Define Macro
Define Class
Define Class
Set Option
Trusted Users
Set Precedence
Define Mailer
Define Header
Set Ruleset
Define Rule
Key File
Syntax
Vlevel[/vendor]
Dxvalue
Ccword1[ word2]...
Fcfile
Ooption=value
Tuser1[ user2...]
Pname=number
Mname, {field=value}
H[?mflag?]name:format
Sn
Rlhs rhs comment
Kname type [argument]
Meaning
Specify version level.
Set macro x to value.
Set class c to word1 word2....
Load class c from file.
Set option to value.
Trusted users are user1 user2....
Set name to precedence number.
Define mailer name.
Set header format.
Start ruleset number n.
Rewrite lhs patterns to rhs format.
Define database name.
Sendmail
10-20
10
Version Level Command
 Vlevel[/vendor]
Example: V8/Berkeley
 Indicates the version level of the configuration
syntax
 V command tells sendmail to support certain
level of syntax and commands.
 Sendmail will report error message during
startup if it can not support the level.
Sendmail
10-21
Define Macro Command
 Careful about name confliction
 Dxvalue
Example: DSmail.mtu.edu
 Define a macro and stores a value
 A macro can be single character or a word enclosed in
curly braces
 Do not use the same name as internal macros when
defining user macros
 Reference the value of a macro as $x
DRalmond
DMnuts.com
DQ$R.$M

$%x is used to expand macros at runtime
Sendmail
10-22
11
Define Macro Command
 Conditionals
DX$g$?x ($x)$.
If x has a value set, X=$g ($x)
If x does not have a value, X=$g
DX$g$?x text1 $| test2 $.
If x is set, X=$g text1
If x is not set, X=$g test2
Sendmail
10-23
Defining Classes
 Classes are used for anything with multiple values.
 Use C command to define a list of value on
one/multiple lines
Cwgoober pea
Or
Cwgoober
Cwpea
 Use F command to read from a file
Fw/etc/mail/local-host-names
 Special pattern matching
 $= matches any value in a class
 $~ symbol matches any value not in a class
 Variable names do not have to be alphabetic characters
Run command grep ‘^[CF]’ sendmail.cf
Sendmail
10-24
12
Setting Options
 Define sendmail environment
 No user defined options.
 Example:
# location of alias file
O AliasFile=/etc/aliases
# temporary file mode
O TempFileMode=0600
# default timeout interval
O Timeout.queuereturn=5d
• Use grep ‘^O’ sendmail.cf to get more
Sendmail
10-25
Defining Trusted Users
 T command defines a list of users who are
trusted to override the sender address
using the mailer –f flag.
Root, uucp, and daemon – must be in
/etc/passwd file.
 Do not modify this list – security issue.
 Run grep “^T” sendmail.cf

Sendmail
10-26
13
Defining Mail Precedence
 Assign priority to messages entering its queue.
The higher the number, the greater the
precedence.
 Pname=number
Pfirst-class=0
Pspecial-delivery=100
Plist=-30
Pbulk=-60
Pjunk=-100
 The default precedence of a message is 0
 To specify a desired precedence, add a
precedence header to the outbound messages.
Sendmail
10-27
Defining mail headers
 The H command defines the format of header
lines that sendmail inserts into messages.


Only controls header insertion
If a header is received in the input, it is passed to the
output regardless of header flag settings.
 H[?mflag?]name:format
 It’s unlikely you’ll need to change them
grep ‘^H’ sendmail.cf
H?P?Return-Path: <$g>
HReceived: $?sfrom $s $.$?_($?s$|from $.$_)
H?D?Resent-Date: $a
H?D?Date: $a
H?F?Resent-From: $?x$x <$g>$|$g$.
H?F?From: $?x$x <$g>$|$g$.
H?x?Full-Name: $x
H?M?Resent-Message-Id: <$t.$i@$j>
H?M?Message-Id: <$t.$i@$j>
Sendmail
10-28
14
Defining Mailers
 Defines the mail delivery programs.
Mname, {field=value}
 Name is an arbitrary name



But, Mailer that delivers local mail to users on the same
machine must be called local.
And, a mailer named local must be defined in sendmail.cf
Other special names are:
• prog #delivers mail to programs
• *file* # sends mail to files
• *include* #directs mail to :include :lists.
 List of “field=value” defines the characteristics of
the mailer.
Sendmail
Field Meaning
Contents
Example
P
Path
Path of the mailer
P=/bin/mail
F
Flags
sendmail flags for this mailer
F=lsDFMe
S
Sender
Rulesets for sender addresses
S=10
R
Recipient
Rulesets for recipient addresses
R=20
A
Argv
The mailer's argument vector
A=sh -c $u
E
Eol
End-of-line string for the mailer
E=\r\n
M
Maxsize
Maximum message length
M=100000
L
Linelimit
Maximum line length
L=990
D
Directory
prog mailer's execution directory
D=$z:/
U
Userid
User and group ID used to run mailer
U=uucp:wheel
N
Nice
nice value used to run mailer
N=10
C
Charset
Content-type for 8-bit MIME characters
C=iso8859-1
T
Type
Type information for MIME errors
T=dns/rfc822/smtp
Sendmail
10-29
10-30
15
Some common mailer definitions
Mlocal, P=/usr/bin/procmail, F=lsDFMAw5:/|@ShP, S=10/30, R=20/40,
T=DNS/RFC822/X-Unix, A=procmail -a $h -d $u
Mprog, P=/bin/sh, F=lsDFMoeu, S=10/30, R=20/40, D=$z:/,
T=X-Unix, A=sh -c $u
Msmtp, P=[IPC], F=mDFMuX, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP, A=IPC $h
Mesmtp,P=[IPC], F=mDFMuXa, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP, A=IPC $h
Msmtp8,P=[IPC], F=mDFMuX8, S=11/31, R=21, E=\r\n, L=990,
T=DNS/RFC822/SMTP, A=IPC $h
Mrelay, P=[IPC], F=mDFMuXa8, S=11/31, R=61, E=\r\n, L=2040,
T=DNS/RFC822/SMTP, A=IPC $h
Sendmail
10-31
Rewriting the Mail Address
 Rewrite rules are the heart of sendmail.cf
 What is rule?
• Used to parse email addresses from user mail
programs and rewrite them into the form required by
the mail delivery programs.
• Syntax is:
Rpattern tranformation comment

Pattern is defined using macros, classes,
literals, and special metasymbols.
Sendmail
10-32
16
Symbol
$@
$*
$+
$$=x
$~x
$x
$%x
$!x
$%y
Meaning
Match exactly zero tokens.
Match zero or more tokens.
Match one or more tokens.
Match exactly one token.
Match any token in class x.
Match any token not in class x.
Match all tokens in macro x.
Match any token in the NIS map named in macro x. [17]
Match any token not in the NIS map named in macro x.[17]
Match any token in the NIS hosts.byname map.[17]
Sendmail
10-33
Pattern matching
 What is operator?
• Defined in option OperatorChars: . % @ [ , etc.
 What is token?
 A string of characters in an email address
delimited by an operator.
 Operators are also counted as tokens
 For example, becky@rodent.wrotethebook.com
Contains seven tokens: becky, @, rodent, . ,
wrotethebook, . , com
And match the pattern $-@$+
Sendmail
10-34
17
Pattern matching
 What is indefinite tokens?
 The strings from the address that match the
meta symbols are assigned to indefinite tokens
– may contain more than one token value.
 Identified numerically: $1, $2, etc.
 For example, becky@rodent.wrotethebook.com
Contains seven tokens: becky, @, rodent, . ,
wrotethebook, . , com
And match the pattern $-@$+
$1 has one token, that is bechy
$2 has three tokens, which are rodent, wrotethebook and
com.
Sendmail
10-35
Transforming the Address
 How are rules being used?
 Pattern matching
 Repeated process of matching and rewriting
 Transformation field is defined using literals,
macros, and special metasymbols
 Addresses are always processed by several
rewrite rules.
Symbol
Meaning
Substitute
indefinite token n.
$n
$[name$]
Substitute the canonical form of name.
$(map key $@argument $:default$) Substitute a value from database map indexed by key.
Call ruleset n.
$>n
$@
Terminate ruleset.
$:
Terminate rewrite rule.
Sendmail
10-36
18
Transforming the address
Note: See page 313-317 for more about transforming
Sendmail
10-37
Set Ruleset command
 Rulesets are groups of associated rewrite rules
that can be referenced by a name or a number.
 S command marks the beginning of a ruleset and
name I.
Sname=number
or
Sn
 Can be thought of as subroutines designed to
process mail addresses
 Rulesets are called



From mailer definition
Individual rewrite rules
Directly by sendmail
Sendmail
10-38
19
Special rulesets called directly by sendmail
Sendmail
10-39
Modifying a sendmail.cf
 Let’s work on a example.
On Linux, configure for rodent.wrotethebook.com
Modifying the local information.
• Class w is the full set of hostnames for which this system accepts
mail.
• On system crab
Cwlocalhost wtb-gw wtb-gw.writethebook.com
Mail addressed to user@wtb-gw.writethebook.com would be
accepted by crab and not rejected as being addressed to the
wrong host.
• Test is using “sendmail –bt –d0.4” for some values.
• Change the version number

Modifying the options
• Don’t modify them if they are right.
Sendmail
10-40
20
Testing sendmail.cf
Argument
-t
-bt
-bv
-bp
-Cfile
-dlevel
-Ooption=value
-e
-v
Function
Send to everyone listed in To:, Cc:, and Bcc:.
Run in test mode.
Verify addresses; don't collect or deliver mail.
Print the mail queue.
Use file as the configuration file.
Set debugging level.
Set option to the specified value.
Defines how errors are returned.
Run in verbose mode.
Sendmail
10-41
Sendmail
10-42
Spam
 MTU spam filter: IronPort
 SpamAssissin
 Awarding winning
 Open Source Mail filter
 Features
•
•
•
•
•
•
•
•
Header tests
Body phrase tests
Bayesian filtering
Automatic address whitelist/blacklist
Manual address whitelist/blacklist
Collaborative spam identication database
DNS blocklists
Character sets and Locales
21
Sendmail macros
 FEATURE(`use_cw_file`)
 FEATURE(`redirect`)
 Aliase: smithj: joe@newsite.com.REDIRECT
 FEATURE(`always_add_domain`)
 FEATURE(`nocanonify`)
 FEATURE(`mailertable`)
 FEATURE(`access_db`,`hash
/etc/mail/access`)
 FEATURE(`virtusertable`)
Sendmail
10-43
Sendmail macros
 MASQUERADE_AS(`wrotethebook.com`)
 Define(‘MAIL_HUB’,`smpt:mailhub.csl.color
ado.edu`)
 Define(`SMART_HOST`,’smpt:mailhub.csl.
colorado.edu`)
Sendmail
10-44
22
Summary
 Sendmail
 Sends/receives SMTP mail - daemon
 Process mail aliases – aliase file
 Interfaces between user mail agents, mail
delivery agents – sendmail.cf
•
•
•
•
Sendmail.cf has very term command syntax
M4 macro processor
Interactive testing tool
Very little need to be changed from the sample
configuration which comes with the package.
Sendmail
10-45
23
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertising