@Override public Response onConnect(SMTPSession session) { return new SMTPResponse("451", "Bye Bye"); } };
@Override protected Response doCoreCmd(SMTPSession session, String command, String parameters) { StringBuilder result = new StringBuilder(); result.append(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD)).append(" Command ").append(command).append(" unrecognized."); return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, result); }
@Override public Response onConnect(SMTPSession session) { return new SMTPResponse("554", "Bye Bye"); } };
@Override public Response onConnect(SMTPSession session) { return new SMTPResponse("451", "Bye Bye"); } };
@Override public Response onConnect(SMTPSession session) { return new SMTPResponse("554", "Bye Bye"); } };
@Override protected Response doCoreCmd(SMTPSession session, String command, String parameters) { session.setAttachment(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME, ProtocolSession.State.Connection); StringBuilder response = new StringBuilder(); response.append(session.getConfiguration().getHelloName()).append( " Hello ").append(parameters).append(" [").append( session.getRemoteAddress().getAddress().getHostAddress()).append("])"); return new SMTPResponse(SMTPRetCode.MAIL_OK, response); }
/** * Handler method called upon receipt of a EHLO command. Responds with a * greeting and informs the client whether client authentication is * required. * * @param session * SMTP session object * @param argument * the argument passed in with the command by the SMTP client */ private Response doEHLO(SMTPSession session, String argument) { SMTPResponse resp = new SMTPResponse(SMTPRetCode.MAIL_OK, new StringBuilder(session.getConfiguration().getHelloName()).append(" Hello ").append(argument) .append(" [") .append(session.getRemoteAddress().getAddress().getHostAddress()).append("])")); session.setAttachment(SMTPSession.CURRENT_HELO_MODE, COMMAND_NAME, State.Connection); processExtensions(session, resp); return resp; }
/** * Handler method called upon receipt of a MAIL command. Sets up handler to * deliver mail as the stated sender. * * @param session * SMTP session object * @param argument * the argument passed in with the command by the SMTP client */ private Response doMAIL(SMTPSession session, String argument) { StringBuilder responseBuffer = new StringBuilder(); MaybeSender sender = (MaybeSender) session.getAttachment(SMTPSession.SENDER, State.Transaction); responseBuffer.append( DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_OTHER)) .append(" Sender <"); if (sender != null) { responseBuffer.append(sender.asString()); } responseBuffer.append("> OK"); return new SMTPResponse(SMTPRetCode.MAIL_OK, responseBuffer); }
@Override public Response onConnect(SMTPSession session) { String smtpGreeting = session.getConfiguration().getGreeting(); SMTPResponse welcomeResponse; // if no greeting was configured use a default if (smtpGreeting == null) { // Initially greet the connector welcomeResponse = new SMTPResponse(SMTPRetCode.SERVICE_READY, new StringBuilder(256) .append(session.getConfiguration().getHelloName()) .append(" ").append(getServiceType(session)).append(" Server (") .append(session.getConfiguration().getSoftwareName()) .append(") ready")); } else { welcomeResponse = new SMTPResponse(SMTPRetCode.SERVICE_READY,smtpGreeting); } return welcomeResponse; }
/** * Handler method called upon receipt of a QUIT command. This method informs * the client that the connection is closing. * * @param session * SMTP session object * @param argument * the argument passed in with the command by the SMTP client */ private Response doQUIT(SMTPSession session, String argument) { if ((argument == null) || (argument.length() == 0)) { StringBuilder response = new StringBuilder(); response.append( DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.UNDEFINED_STATUS)).append(" ").append( session.getConfiguration().getHelloName()).append( " Service closing transmission channel"); SMTPResponse ret = new SMTPResponse(SMTPRetCode.SYSTEM_QUIT, response); ret.setEndSession(true); return ret; } else { return SYNTAX_ERROR; } }
DSNStatus.ADDRESS_VALID)) .append(" Recipient <").append(recipientAddress).append("> OK"); return new SMTPResponse(SMTPRetCode.MAIL_OK, response);
/** * Handler method called upon receipt of a DATA command. Reads in message * data, creates header, and delivers to mail server service for delivery. * * @param session SMTP session object * @param argument the argument passed in with the command by the SMTP client */ @Override protected SMTPResponse doDATA(SMTPSession session, String argument) { try { MimeMessageInputStreamSource mmiss = new MimeMessageInputStreamSource(MailImpl.getId()); session.setAttachment(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE, mmiss, State.Transaction); } catch (Exception e) { LOGGER.warn("Error creating mimemessagesource for incoming data", e); return new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unexpected error preparing to receive DATA."); } // out = new PipedOutputStream(messageIn); session.pushLineHandler(getLineHandler()); return new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>"); }
/** * Handler method called upon receipt of a DATA command. * Reads in message data, creates header, and delivers to * mail server service for delivery. * * @param session SMTP session object * @param argument the argument passed in with the command by the SMTP client */ protected SMTPResponse doDATA(SMTPSession session, String argument) { try { MimeMessageInputStreamSource mmiss = new MimeMessageInputStreamSource(mailServer.getId()); session.getState().put(SMTPConstants.DATA_MIMEMESSAGE_STREAMSOURCE, mmiss); } catch (MessagingException e) { session.getLogger().warn("Error creating mimemessagesource for incoming data",e); return new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unexpected error preparing to receive DATA."); } // out = new PipedOutputStream(messageIn); session.pushLineHandler(getLineHandler()); return new SMTPResponse(SMTPRetCode.DATA_READY, "Ok Send data ending with <CRLF>.<CRLF>"); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { Channel channel = ctx.getChannel(); if (e.getCause() instanceof TooLongFrameException) { ctx.getChannel().write(new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, "Line length exceeded. See RFC 2821 #4.5.3.1.")); } else { if (channel.isConnected()) { ctx.getChannel().write(new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to process request")); } logger.debug("Unable to process request", e.getCause()); cleanup(channel); channel.close(); } super.exceptionCaught(ctx, e); }
return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS,"Could not decode parameters for AUTH " + authType);
@Override protected Response processExtensions(SMTPSession session, MailEnvelopeImpl mail) { LMTPMultiResponse mResponse = null; Iterator<MailAddress> recipients = mail.getRecipients().iterator(); while (recipients.hasNext()) { MailAddress recipient = recipients.next(); Response response = null; for (DeliverToRecipientHook handler: handlers) { response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(handler.deliver(session, recipient, mail)); if (response != null) { break; } } if (response == null) { // Add some default response for not handled responses response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + "Temporary error deliver message to " + recipient); } if (mResponse == null) { mResponse = new LMTPMultiResponse(response); } else { mResponse.addResponse(response); } } return mResponse; }
SMTPResponse response = new SMTPResponse(smtpReturnCode, smtpDescription); SMTPResponse response = new SMTPResponse(""); response.setEndSession(true); return response;
/** * Convert the HookResult to SMTPResponse using default values. Should be override for using own values * * @param result HookResult * @return SMTPResponse */ public static SMTPResponse calcDefaultSMTPResponse(HookResult result) { if (result != null) { HookReturnCode returnCode = result.getResult(); String smtpReturnCode = OptionalUtils.or( Optional.ofNullable(result.getSmtpRetCode()), retrieveDefaultSmtpReturnCode(returnCode)) .orElse(null); String smtpDescription = OptionalUtils.or( Optional.ofNullable(result.getSmtpDescription()), retrieveDefaultSmtpDescription(returnCode)) .orElse(null); if (canBeConvertedToSmtpAnswer(returnCode)) { SMTPResponse response = new SMTPResponse(smtpReturnCode, smtpDescription); if (returnCode.isDisconnected()) { response.setEndSession(true); } return response; } } return null; }
response = new SMTPResponse(SMTPRetCode.MAIL_OK, DSNStatus.getStatus(DSNStatus.SUCCESS,DSNStatus.CONTENT_OTHER)+" Message received"); response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR,DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + " Temporary error deliver message to " + recipient);
@Override protected Response processExtensions(SMTPSession session, Mail mail) { LMTPMultiResponse mResponse = null; // build a wrapper around the Mail final ReadOnlyMailEnvelope env = new ReadOnlyMailEnvelope(mail); for (MailAddress recipient : mail.getRecipients()) { Response response = null; for (DeliverToRecipientHook handler : handlers) { response = AbstractHookableCmdHandler.calcDefaultSMTPResponse(handler.deliver(session, recipient, env)); if (response != null) { break; } } if (response == null) { // Add some default response for not handled responses response = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + "Temporary error deliver message to " + recipient); } if (mResponse == null) { mResponse = new LMTPMultiResponse(response); } else { mResponse.addResponse(response); } } return mResponse; }