FileDocCategorySizeDatePackage
SendMailHandler.javaAPI DocApache James 2.3.15378Fri Jan 12 12:56:26 GMT 2007org.apache.james.smtpserver

SendMailHandler

public class SendMailHandler extends org.apache.avalon.framework.logger.AbstractLogEnabled implements org.apache.avalon.framework.service.Serviceable, MessageHandler
Adds the header to the message

Fields Summary
private org.apache.james.services.MailServer
mailServer
Constructors Summary
Methods Summary
public voidonMessage(SMTPSession session)
Adds header to the message

see
org.apache.james.smtpserver#onMessage(SMTPSession)

        getLogger().debug("sending mail");

        Mail mail = session.getMail();
        
        String responseString = null;
        try {
            mailServer.sendMail(mail);
            Collection theRecipients = mail.getRecipients();
            String recipientString = "";
            if (theRecipients != null) {
                recipientString = theRecipients.toString();
            }
            if (getLogger().isInfoEnabled()) {
                StringBuffer infoBuffer =
                     new StringBuffer(256)
                         .append("Successfully spooled mail ")
                         .append(mail.getName())
                         .append(" from ")
                         .append(mail.getSender())
                         .append(" on ")
                         .append(session.getRemoteIPAddress())
                         .append(" for ")
                         .append(recipientString);
                getLogger().info(infoBuffer.toString());
            }
         } catch (MessagingException me) {
              // Grab any exception attached to this one.
              Exception e = me.getNextException();
              // If there was an attached exception, and it's a
              // MessageSizeException
              if (e != null && e instanceof MessageSizeException) {
                   // Add an item to the state to suppress
                   // logging of extra lines of data
                   // that are sent after the size limit has
                   // been hit.
                   session.getState().put(SMTPSession.MESG_FAILED, Boolean.TRUE);
                   // then let the client know that the size
                   // limit has been hit.
                   responseString = "552 "+DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.SYSTEM_MSG_TOO_BIG)+" Error processing message.";
                   StringBuffer errorBuffer =
                     new StringBuffer(256)
                         .append("Rejected message from ")
                         .append(session.getState().get(SMTPSession.SENDER).toString())
                         .append(" from host ")
                         .append(session.getRemoteHost())
                         .append(" (")
                         .append(session.getRemoteIPAddress())
                         .append(") exceeding system maximum message size of ")
                         .append(session.getConfigurationData().getMaxMessageSize());
                   getLogger().error(errorBuffer.toString());
              } else {
                   responseString = "451 "+DSNStatus.getStatus(DSNStatus.TRANSIENT,DSNStatus.UNDEFINED_STATUS)+" Error processing message.";
                   getLogger().error("Unknown error occurred while processing DATA.", me);
              }
              session.writeResponse(responseString);
              return;
         }
         responseString = "250 "+DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received";
         session.writeResponse(responseString);

    
    
public voidservice(org.apache.avalon.framework.service.ServiceManager serviceManager)

see
org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)

        mailServer = (MailServer) serviceManager.lookup(MailServer.ROLE);