Why is the SMTP server not receiving a DATA command?

I encode POP3 and SMTP servers using Java for a university project. I can send emails using my SMTP server through a client (i.e. Thunderbird) and my server sends them without any problems.

When an external sender agent, such as gmail or hotmail, tries to send an email using my SMTP server, it does not end the connection because it sends the QUIT command after the MAIL command. Why does an external agent do this? Didn't I obey the SMTP protocol?

The problem is that when I get a connection to an external server that wants to send me mail, the following happens (me: my SMTP server, sender: sending agent). Here is a gmail agent example.


sender: establishes a connection me: 220 Welcome sender: HELO agent id me: 250 Fine sender: MAIL FROM:< address@gmail.com > me (after address verification): 250 sender: QUIT me: 221 

Relevant code fragments (the full class code is located at http://code.google.com/p/sd-mail-server-claudiani-ferrari/source/browse/src/controller/smtp/SMTPCommandHandler.java?repo=mailserver )

 private void MAILCommand(CommunicationHandler communicationHandler, BufferedOutputStream writer, PersistanceManager persistanceManager, String clientId, String argument) { String address = getAddressFromArgument(argument); if (!isValidAddress(address, persistanceManager)) { communicationHandler.sendResponse(writer, SMTPCode.SYNTAX_ERROR.toString(), "Address is not valid."); return; } // Initialize data persistanceManager.create(StorageLocation.SMTP_TEMP_MESSAGE_STORE, FieldName.getSMTPTempTableFromFieldOnly(), clientId, address); communicationHandler.sendResponse(writer, SMTPCode.OK.toString(), ""); } private void RCPTCommand(CommunicationHandler communicationHandler, BufferedOutputStream writer, PersistanceManager persistanceManager, String clientId, String argument) { String address = getAddressFromArgument(argument); // Check the address if (!isValidAddress(address, persistanceManager)) { communicationHandler.sendResponse(writer, SMTPCode.SYNTAX_ERROR.toString(), "Address is not valid."); return; } persistanceManager.addToSet(StorageLocation.SMTP_TEMP_MESSAGE_STORE, clientId, FieldName.SMTP_TEMP_TO_ADDRESSES, address); communicationHandler.sendResponse(writer, SMTPCode.OK.toString(), ""); } private void DATACommand(CommunicationHandler communicationHandler, BufferedOutputStream writer, PersistanceManager persistanceManager, String clientId) { communicationHandler.sendResponse(writer, SMTPCode.INTERMEDIATE_REPLY.toString(), "Start mail input; end with [CRLF].[CRLF]"); } 
+4
source share
1 answer

Have you tried to answer 250 OK instead of 250 ? RFC 2821 says that this should be the response of the MAIL FROM :

If accepted, the SMTP server will return a 250 OK . If the mailbox specification is unsuitable for some reason, the server MUST return a response indicating whether

Your email client may be satisfied with viewing 250 , while Google / Hotmail may expect 250 OK .

Edit

I think the text string is not optional in this case, see section 4.2 of RFC 2821 :

An SMTP response consists of a three-digit number (transmitted as three numeric characters) followed by text, unless otherwise specified in this document.

Current RFC 5321 suggests that clients should not accept text:

The SMTP client SHOULD determine its actions only by the response code, and not by the text (except for the "change of address" 251 and 551 and, if necessary, the answers 220, 221 and 421); in general, any text, including text in general (although senders SHOULD NOT send unencrypted codes) MUST be acceptable. The space (space) after the response code is considered part of the text. As soon as possible, the SMTP receiver SHOULD check the first digit (indication of severity) of the response code.

+1
source

Source: https://habr.com/ru/post/1435551/


All Articles