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]"); }