Bogdan Gusiev
Bogdan Gusiev

Reputation: 8305

SMTP protocol: multiple mails per connection

I need to implement support of multiple messages per one connection for my SMTP server.

Every message ends with:

data
<<content>>
.

And it's logically that protocol state should be reset to "after receive authentication" point. Is it correct?

The question: Is it possible that any client sends message content with multiple data commands? Does the standard allow it?

Upvotes: 4

Views: 6204

Answers (1)

SimonJ
SimonJ

Reputation: 21306

From RFC2821 ("Simple Mail Transfer Protocol"):

The mail data is terminated by a line containing only a period, that is, the character sequence "." (see section 4.5.2).

...

Receipt of the end of mail data indication requires the server to process the stored mail transaction information. This processing consumes the information in the reverse-path buffer, the forward-path buffer, and the mail data buffer, and on the completion of this command these buffers are cleared.

i.e. after <CRLF>.<CRLF> is received, the server consumes the mail data and clears its buffers; hence the client cannot then send more content associated with the message, since the server will have forgotten about the message.

...

Once started, a mail transaction consists of a transaction beginning command, one or more RCPT commands, and a DATA command, in that order.

...

MAIL (or SEND, SOML, or SAML) MUST NOT be sent if a mail transaction is already open, i.e., it should be sent only if no mail transaction had been started in the session, or it the previous one successfully concluded with a successful DATA command, or if the previous one was aborted with a RSET.

i.e. MAIL begins a new mail transaction, and a successful DATA command (terminated by <CRLF>.<CRLF>) concludes it; the client may then send another message.


From RFC4954 ("SMTP Service Extension for Authentication"):

After an AUTH command has been successfully completed, no more AUTH commands may be issued in the same session. After a successful AUTH command completes, a server MUST reject any further AUTH commands with a 503 reply.

i.e. authentication takes place at most once per session, and applies until the end of that session.

Upvotes: 14

Related Questions