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]");
}
Have you tried replying with
250 OKinstead of just250? RFC 2821 says that this should be the reply of aMAIL FROMline:Your mail client might be satisfied with seeing
250, while Google/Hotmail might expect250 OK.Edit
I think the text string isn’t optional in this case, see section 4.2 of RFC 2821:
The current RFC 5321 suggests that clients should accept no text: