@Test public void testInvalidSenderDomainReject() throws Exception { ValidSenderDomainHandler handler = createHandler(); SMTPSession session = setupMockedSession(new MailAddress("invalid@invalid")); MaybeSender sender = session.getAttachment(SMTPSession.SENDER, State.Transaction).get(); HookReturnCode response = handler.doMail(session, sender).getResult(); assertThat(HookReturnCode.deny()).describedAs("Blocked cause we use reject action").isEqualTo(response); }
@Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } }
ValidSenderDomainHandler implements MailHook { @Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } } }
ValidSenderDomainHandler implements MailHook { @Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } }  }
ValidSenderDomainHandler implements MailHook { @Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } }  @Override HookResult doMail(SMTPSession session, MaybeSender sender); }
ValidSenderDomainHandler implements MailHook { @Override public HookResult doMail(SMTPSession session, MaybeSender sender) { if (!sender.isNullSender() && !hasMXRecord(session,sender.get().getDomain().name())) { return HookResult.builder() .hookReturnCode(HookReturnCode.deny()) .smtpReturnCode(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS) .smtpDescription(DSNStatus.getStatus(DSNStatus.PERMANENT,DSNStatus.ADDRESS_SYNTAX_SENDER) + " sender " + sender + " contains a domain with no valid MX records") .build(); } else { return HookResult.DECLINED; } }  @Override HookResult doMail(SMTPSession session, MaybeSender sender);  }