@Override @SuppressWarnings("unchecked") public HookResult doRcpt(SMTPSession session, MaybeSender sender, MailAddress rcpt) { Collection<MailAddress> rcptList = (Collection<MailAddress>) session.getAttachment(SMTPSession.RCPT_LIST, State.Transaction); // Check if the recipient is already in the rcpt list if (rcptList != null && rcptList.contains(rcpt)) { StringBuilder responseBuffer = new StringBuilder(); responseBuffer.append(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID)) .append(" Recipient <") .append(rcpt.toString()) .append("> OK"); LOGGER.debug("Duplicate recipient not add to recipient list: {}", rcpt); return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpReturnCode(SMTPRetCode.MAIL_OK) .smtpDescription(responseBuffer.toString()) .build(); } return HookResult.DECLINED; } }
@Override public HookResult doAuth(SMTPSession session, String username, String password) { try { if (users.test(username, password)) { session.setUser(username); session.setRelayingAllowed(true); return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpDescription("Authentication Successful") .build(); } } catch (UsersRepositoryException e) { LOGGER.info("Unable to access UsersRepository", e); } return HookResult.DECLINED; }
/** * Adds header to the message * */ @Override public HookResult onMessage(SMTPSession session, Mail mail) { LOGGER.debug("sending mail"); try { queue.enQueue(mail); LOGGER.info("Successfully spooled mail {} from {} on {} for {}", mail.getName(), mail.getMaybeSender(), session.getRemoteAddress().getAddress(), mail.getRecipients()); } catch (MessagingException me) { LOGGER.error("Unknown error occurred while processing DATA.", me); return HookResult.builder() .hookReturnCode(HookReturnCode.denySoft()) .smtpDescription(DSNStatus.getStatus(DSNStatus.TRANSIENT, DSNStatus.UNDEFINED_STATUS) + " Error processing message.") .build(); } return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpDescription(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.CONTENT_OTHER) + " Message received") .build(); }
mailboxManager.endProcessingRequest(mailboxSession); return HookResult.builder() .hookReturnCode(HookReturnCode.ok()) .smtpReturnCode(SMTPRetCode.MAIL_OK) .smtpDescription(DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.CONTENT_OTHER) + " Message received")