Domanda

I am coding POP3 and SMTP servers using Java for an university project. I can send emails using my SMTP server via a client (ie: Thunderbird) and my server sends them without any problem.

When an external sender agent, like gmail or hotmail, tries to send an email using my SMTP server, it does not complete the communication because it sends the QUIT command after the MAIL command. Why the external agent does that? Didn't I obey to the SMTP protocol?

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


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 snippets (full class code is 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]");
}
È stato utile?

Soluzione

Have you tried replying with 250 OK instead of just 250 ? RFC 2821 says that this should be the reply of a MAIL FROM line:

If accepted, the SMTP server returns a 250 OK reply. If the mailbox specification is not acceptable for some reason, the server MUST return a reply indicating whether the

Your mail client might be satisfied with seeing 250, while Google/Hotmail might expect 250 OK.

Edit

I think the text string isn't optional in this case, see section 4.2 of RFC 2821:

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

The current RFC 5321 suggests that clients should accept no text:

An SMTP client MUST determine its actions only by the reply code, not by the text (except for the "change of address" 251 and 551 and, if necessary, 220, 221, and 421 replies); in the general case, any text, including no text at all (although senders SHOULD NOT send bare codes), MUST be acceptable. The space (blank) following the reply code is considered part of the text. Whenever possible, a receiver- SMTP SHOULD test the first digit (severity indication) of the reply code.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top