		
	Delivery 

------------------------------------------------------------
1	Overview

2	Case Study
2.1	SMTP logfile
2.2	Delivery After Sorting
2.3	$OUTGOING_ADDRESS: shorten perl life time
2.4	Disable PIPELINING
2.5	Use Plural Mta'S On Plural Hosts
2.6	VERPs

3	Internal
3.1	SMTP library
3.2	Secondary SMTP Servers
3.4	On The Same Mx
3.5	MCI Cache
3.5	MCI Cache
3.7	Blocking Stage Of Delivery Process

4	Relaying based on RFC821
4.1	Relay Configurations In Actives File
4.2	Default relay server	
4.3	Relay Based On Actives File (Sendmail 5.X)
4.4	Cf (By motonori@wide.ad.jp) Style Relay Configurations

5	Q&A
5.1	use my own MTA without root priviledge
5.2	call smtpfeed directly?
5.3	MTA gambles
------------------------------------------------------------


1	Overview

Filtering => 

Relay  => 4

2	Case Study

2.1	SMTP logfile

For debug, FML logs SMTP session log in $SMTP_LOG. If you do not want
the logging, please set

	$NOT_TRACE_SMTP = 1; 

2.2	Delivery After Sorting

If

	$SMTP_SORT_DOMAIN

is defined, delivery routine works after sorting recipients by domain.

2.3	$OUTGOING_ADDRESS: shorten perl life time

$OUTGOING_ADDRESS is a simple :include: style ML. The member is
recipients of this ML. Fml generates the file from recipient lists,
@ACTIVE_LISTS files. 

   if ($USE_OUTGOING_ADDRESS) {
	1. fml sends article to $OUTGOING_ADDRESS.
	   Hence perl dies here!
	2. MTA expands the include and delivers the article to ML members.
   }

[How to configure]

0.	Consider elena ML

1.	make include examles

   % cd /var/spool/ml/elena
   % make outgoing 

You can see elena/include-outgoing file.

2.	add elena-outgogin to /etc/aliases and run newaliases

   elena-outgoing: :include:/var/spool/ml/elena/include-outgoing

3.	run 'makefml config' to enable this function

	-> OPTIONS -> SMTP -> USE_OUTGOING_ADDREESS -> "y"

$USE_OUTGOING_ADDDRESS changes from zero/null to 1.

2.4	Disable PIPELINING

	$NOT_USE_ESMTP_PIPELINING = 1;

2.5	Use Plural Mta'S On Plural Hosts

To use plural MTA on plural hosts (N hosts), set the number of hosts
in

	$MCI_SMTP_HOSTS = N;

and configure an array @HOSTS filled with at least N hostnames.

   @HOSTS = (machine-1.domain, machine-2.domain, machine-3.domain, ...);

fml.pl uses MTA's on $HOST and @HOSTS in delivery.

If the total number of $HOST and @HOSTS < N, fml.pl uses $HOST again
and again. This technique is used as a secondary server in delivery.
When you setup @HOSTS and unset $MCI_SMTP_HOSTS, fml.pl uses $HOST in
usual, but @HOSTS if $HOST is down.

2.6	VERPs

	1;

	$SMTP_SENDER = $MAINTAINER;
	$SMTP_SENDER =~ s/$DOMAINNAME/$myDOMAIN/;
	1;

3	Internal

3.1	SMTP library

FML can connect MTA (Mail Transport Agent) via SMTP (IPC).
libsmtp*.pl are SMTP libraries. The default port is 25/tcp.
You can control the port as $PORT. 

	$PORT 

FML logs a session details in $SMTP_LOG.

	$SMTP_LOG (default "var/log/_smtplog")

If you do not need th session log, set 

	$NOT_TRACE_SMTP 

Which MTA in which hosts FML uses as a distributor? In default, $HOST
is "localhost" (ML server itself). You can use another host by
configuring $HOST.

	$HOST         = 'localhost'; (default)

	$HOST         = 'beth.foo.bar.ac.jp'; (another host)

You requires permission that you can use $HOST as a distributor since
you use the machine resources. 

You can use MTA with another port (not 25/tcp). For example, 10025/tcp

	$HOST         = 'beth.foo.bar.ac.jp:10025'; 

3.2	Secondary SMTP Servers

If you can use several machines as delivery, you can set

   @HOSTS = (machine-1.domain, machine-2.domain, machine-3.domain, ...);

to use machine-* parallelly. FML breaks out recipients up to
$MCI_SMTP_HOSTS groups. Mail to deliver is injected to each MTA on
$HOST and @HOSTS. If all connections to hosts fail, FML tries to send
mail with "sendmail" called as a command.

	$SMTP_SENDER = 'elena-admin@fml.org';

3.4	On The Same Mx

In CHANGES-R5-R8 of Sendmail R8:

   For example, if two sites ``foo.com'' and ``bar.com'' are both
   served by UUNET, they will have the same set of MX hosts and will
   be sent in one transaction.  UUNET will then split the message

Sendmail 5.x requires ordering by domain:

	fukachan@phys.titech.ac.jp	
	Elena@phys.titech.ac.jp	
	cocoa@phys.titech.ac.jp	

3.5	MCI Cache
3.5	MCI Cache

Today sendmail 8.x has parallel connections and re-uses sockets. 
Delivery acceleration codes is called MCI.
Please see deliver() in /usr/src/usr.sbin/sendmail/src/deliver.c.

WIDE-patched sendmail and smtpfeed has more and more elaborate
parallelism of resolver and SMTP connections.

Discussion On Delivery Efficiency

3.7	Blocking Stage Of Delivery Process

The cost of delivery depends on the cost of SMTP connections. To
accelerate each action e.g. DNS, SMTP sessions need to run parallelly
and simultaneously. For example it is good to use "smtpfeed" for
acceleration of delivery. qmail forks plural processes and run
simultaneously ;_;

The tuning of fml.pl codes cannot contribute the delivery acceleration
since delivery speeds are much slower than fml processing time scale.
To accelerate delivery, we can consider a few conditions:

1	plural MTA running on one host. fml.pl uses them simultaneously.
	If the host is enough tough, it is O.K. It is the logic of qmail:)

2	uses plural MTA on different hosts. 
	This works even though hosts are delicate.

3	prepare relay servers, a variation of case 2. 
	This case assumes one smtp session transports a pack of
	plural recipients e.g. one smtp session for a region.

FML prepares variables $MCI_* to use plural MTA for one article.

Today MTA rejects a relay against UCE(SPAM) illegal relay. If you use
relay server, you need to reconfigure MTA's on relay machines.

You can use $DEFAULT_RELAY_SERVER as a default relay server. fml.pl
sends mail to deliver to the default relay server. The server
delivers it.

	$DEFAULT_RELAY_SERVER

	http://www.qmail.org/

4	Relaying based on RFC821

Today we cannot permit relaying against spam mails. If sendmail is not
found, FML tries to use qmail-smtpd, exim.

4.1	Relay Configurations In Actives File

When you can use relay server (here axion.phys.titech.ac.jp), You can
write how to relay in "actives" file, 

	fukachan@phys.titech.ac.jp	r=axion.phys.titech.ac.jp

	address				relay server
	fukachan@phys.titech.ac.jp	r=axion.phys.titech.ac.jp

FML interprets, rewrite and injects this to sendmail as:

	@axion.phys.titech.ac.jp:fukachan@phys.titech.ac.jp

If "actives" file has the following entries

	fukachan@phys.titech.ac.jp	r=axion.phys.titech.ac.jp
	Elena@phys.titech.ac.jp		r=axion.phys.titech.ac.jp
	cocoa@phys.titech.ac.jp		r=axion.phys.titech.ac.jp

FML injects 

	@axion.phys.titech.ac.jp:fukachan@phys.titech.ac.jp
	@axion.phys.titech.ac.jp:Elena@phys.titech.ac.jp
	@axion.phys.titech.ac.jp:cocoa@phys.titech.ac.jp

sendmail 8.x delivery aggregates SMTP sessions to axion.
On axion, MTA segregates it to three mails.

4.2	Default relay server	

You can set up $DEFAULT_RELAY_SERVER. it is used as a default relay
server. FML recognizes all recipients should be delivered via the
relay server. FML interprets entries in "actives" has
r=$DEFAULT_RELAY_SERVER.

	$DEFAULT_RELAY_SERVER

4.3	Relay Based On Actives File (Sendmail 5.X)

	fukachan@phys.titech.ac.jp	r=axion.phys.titech.ac.jp
	Elena@phys.titech.ac.jp		r=axion.phys.titech.ac.jp
	cocoa@phys.titech.ac.jp		r=axion.phys.titech.ac.jp

In Sendmail 5.x, you require additional orderings by relay server in
"actives". 

4.4	Cf (By motonori@wide.ad.jp) Style Relay Configurations

When $RELAY_HACK = 1; is defined and $CF_DEF (CF style static delivery
rule file) exists, FML controls relaying based on it.

CF style example: 
	send e-mail for or.jp domain to mlrelay0.domain0.

	GW smtp-ignmx:  mlrelay0.domain0
	DOM or.jp

CF style example2:
	send mails not for co.jp to mlrelay.domain.
	send e-mail for or.jp domain to mlrelay0.domain0.	 

	NGW smtp-ignmx: mlrelay.domain
	DOM co.jp
	GW smtp-ignmx:  mlrelay0.domain0
	DOM or.jp

SMTP library uses hashes %RELAY_NGW, %RELAY_GW, %RELAY_NGW_DOM for
control of this relay routings.

5	Q&A

5.1	use my own MTA without root priviledge

not in general.

5.2	call smtpfeed directly?

difficult since fml need to do queue management when fml does so.

5.3	MTA gambles

   		@HOSTS = (hostA, hostB, hostC, ...)

	@HOSTS = (hostA, hostB, hostC, ...)
and sort it randomly :-)


		INDEX

_smtplog                                   ...   2.1 
$CF_DEF                                    ...   4.4 
$DEFAULT_RELAY_SERVER                      ...   3.7 4.2 
$HOST                                      ...   3.1 
@HOSTS                                     ...   2.5 3.2 
$HOSTS                                     ...   2.5 
MCI                                        ...   3.5 
MTA (Mail Transport Agent)                 ...   3.1 
mx                                         ...   3.4 
$NOT_TRACE_SMTP                            ...   2.1 
$NOT_TRACE_SMTP                            ...   3.1 
$PORT                                      ...   3.1 
%RELAY_GW                                  ...   4.4 
$RELAY_HACK                                ...   4.4 
%RELAY_NGW                                 ...   4.4 
%RELAY_NGW_DOM                             ...   4.4 
relay hack based on CF (by motonori@wide.ad.jp)   ...   4.4 
SMTP (Simple Mail Transfer Protocol)       ...   3.1 
$SMTP_LOG                                  ...   2.1 3.1 
$SMTP_SORT_DOMAIN                          ...   2.2 
var/log/_smtplog                           ...   2.1 
