Internet Engineering Task Force        A. Durand, F. Dupont, J. G. Myers
INTERNET-DRAFT                             IMAG, INRIA Rocquencourt, CMU
                                                         September, 1994


                         SMTP 521 reply code
               <draft-ietf-mailext-smtp-521-02.txt>

1. Status

Distribution of this memo is unlimited.

This document is an Internet Draft.  Internet Drafts are working
documents of the Internet Engineering Task Force (IETF), its Areas, and
its Working Groups.  Note that other groups may also distribute working
documents as Internet Drafts.

Internet Drafts are draft documents valid for a maximum of six months.
Internet Drafts may be updated, replaced, or obsoleted by other
documents at any time.  It is inappropriate to use Internet Drafts as
reference material or to cite them other than as ``work in progress.''

To learn the current status of any Internet-Draft, please check
the ``1id-abstracts.txt'' listing contained in the Internet-
Drafts Shadow Directories on ds.internic.net (US East Coast),
nic.nordu.net (Europe), ftp.isi.edu (US West Coast), or
munnari.oz.au (Pacific Rim).




2. Abstract

This memo defines a new SMTP ([1]) reply code, 521, which an
Internet host may use to indicate that it does not accept
incoming mail.


3. Motivations

Hosts on the Internet have shifted from large, general-purpose hosts
to smaller, more specialized hosts.  There is an increasing number of
hosts which are dedicated to specific tasks, such as serving NTP
or DNS.  These dedicated hosts frequently do not provide mail service.

Usually, these hosts do not run an SMTP server.  Unfortunately, users
will occasionally misaddress mail to these hosts.  SMTP clients
attempting to deliver this misaddressed mail must treat the lack of an
SMTP server on the host as a temporary error. They must queue the mail
for later delivery, should an SMTP server be started at a later time.
This causes the mail to remain queued for days, until it is returned
with what is usually a confusing error message.





Expires February 1995                                          [Page 1]


4. SMTP client behavior

The SMTP 521 reply code directs any SMTP client to immediately return
the mail with an appropriate non-delivery report. SMTP clients should
not make further attempts to deliver the mail before returning it.
In particular, SMTP clients should not attempt to deliver the mail
to another MX site for the domain.



5. SMTP server behavior

A host may indicate that it does not accept mail by sending an initial
521 "Host does not accept mail" reply to an incoming SMTP connection.
The official name of the server host or its IP address MUST be sent as
the first word following the reply code.


For example: 521 canon.inria.fr does not accept mail

After issuing the initial 521 reply, the server host MUST do one of
the following two options:

a) Close the SMTP connection.
b) Read commands, issuing 521 replies to all commands except QUIT.
If the SMTP client does not issue the QUIT command after a reasonable
time, the SMTP server MUST time out and close the connection.
A suggested time-out value is 5 minutes.


DISCUSSION:

    When an SMTP server closes the connection immediatly after issuing
    the initial 521 reply, some existing SMTP clients treat the
    condition as a transient error and requeue the mail for later
    delivery.  If the SMTP server leaves the connection open, those
    clients immediately send the QUIT command and return the mail.



6. Security considerations

A SMTP server which simply emits fixed strings in response to
incoming connection should provide significantly fewer opportunities
for security problems than a minimal SMTP implementation.


7. Example implementation

A simple daemon written in Perl is given below as an example.
It is derived from the examples given in [2] and is currently
running on our NTP stratum 1 server: canon.inria.fr.

The authors disclaim all warranties with regard to this software,
including all implied warranties of merchantability and fitness.


Expires February 1995                                          [Page 2]


#!/usr/local/bin/perl
eval 'sub WNOHANG {1;}';
eval 'sub SOL_SOCKET {0xffff;}';
eval 'sub SO_REUSEADDR {0x0004;}';
eval 'sub EINTR {4;}';

$SIG{'CHLD'} = 'reapchild';
$hostname="canon.inria.fr";
$port = 25;
$smtpTimeOut = 300; # 5 minutes
$AF_INET = 2;
$SOCK_STREAM = 1;
$sockaddr = 'S n a4 x8';
($name, $aliases, $proto) = getprotobyname('tcp');
$this = pack($sockaddr, $AF_INET, $port, "\0\0\0\0");
select(NS); $| = 1; select(stdout);
socket(S, $AF_INET, $SOCK_STREAM, $proto) || die "socket: $!";
setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, "1");
bind(S,$this) || die "bind: $!";
listen(S,5) || die "connect: $!";
select(S); $| = 1; select(stdout);

for(;;) {
    unless ($addr = accept(NS,S)) {;
        if ($!  == &EINTR) { next;}
        else {die "accept: $!";}
        }
    FORK:
    if ($pid = fork) {
        # parent process
        close(NS);
        }
    elsif (defined $pid) {
        # child process
        $SIG{'ALRM'} = 'timeout';
        alarm $smtpTimeOut;  # Timeout
        print NS "521 $hostname does not accept mail.\r\n";
        while (<NS>) {
            last if /^quit/i;
            print NS
            "521 $hostname does not accept mail.\r\n";
            }
        print NS "221 $hostname\r\n";
        close(NS);
        exit;
        }
    elsif ($! =~ /No more proces/i) {
        # EAGAIN, supposedly recoverable fork error
        sleep 5;
        redo FORK;
    }
    else {
        # unrecoverable fork error, just die!
        die "Can't fork: $!";
        }
}

Expires February 1995                                          [Page 3]


sub reapchild{
    while (1) {
    $pid = waitpid(-1,$WNOHANG);
    last if ($pid < 1);
    }
}

sub timeout{
    print NS "521 $hostname timeout, closing connection.\r\n";
    close(NS);
    exit;
}


8. Author addresses

Alain Durand
Institut de Mathematiques Appliquees de Grenoble (IMAG)
BP 53 38041 Grenoble CEDEX 9 France
Phone : +33 76 51 46 00
E-Mail: Alain.Durand@imag.fr

Francis Dupont
Institut National de Recherche en Informatique et en Automatique
B.P. 105 / 78153 Le Chesnay CEDEX France
Fax   : +33 1 39 63 53 30
Phone : +33 1 39 63 52 13
E-Mail: Francis.Dupont@inria.fr

John G. Myers
Carnegie-Mellon University
5000 Forbes Ave.  Pittsburgh PA, 15213-3890
E-mail: jgm+@cmu.edu



9. References

[1] J.B. Postel. Simple Mail Transfer Protocol, Request For Comments 821
STD 10, (August, 1982).

[2] L. Wall, R. Schwartz. Programming Perl, O'Reilly and Associates Inc,















Expires February 1995                                          [Page 4]