コード例 #1
0
  private void checkRejectOneRecipientAfterData(AssertCheck check) throws Exception {
    int port = TestUtils.getFreePort();

    NettyServer smtpServer =
        create(
            new DeliverToRecipientHook() {

              @Override
              public HookResult deliver(
                  SMTPSession session, MailAddress address, MailEnvelope env) {
                if (address.toString().equals("*****@*****.**")) {
                  return new HookResult(HookReturnCode.DENY);
                }
                return new HookResult(HookReturnCode.OK);
              }
            });

    smtpServer.setListenAddresses(new InetSocketAddress(port));

    smtpServer.bind();

    SMTPClientTransport transport = createSMTPClient();
    SMTPDeliveryAgent c = createAgent(transport);

    try {
      SMTPDeliveryAgentConfigImpl conf = createConfig();
      SMTPDeliveryEnvelope transaction =
          new SMTPDeliveryEnvelopeImpl(
              "*****@*****.**",
              Arrays.asList(new String[] {"*****@*****.**", "*****@*****.**", "*****@*****.**"}),
              new SMTPMessageImpl(new ByteArrayInputStream("msg".getBytes())));

      SMTPClientFuture<Collection<FutureResult<Iterator<DeliveryRecipientStatus>>>> future =
          c.deliver(new InetSocketAddress(port), conf, transaction);
      check.onSMTPClientFuture(future);

    } finally {
      smtpServer.unbind();
      transport.destroy();
    }
  }
コード例 #2
0
 @Override
 protected ProtocolServer createServer(Protocol protocol, InetSocketAddress address) {
   NettyServer server = new NettyServer(protocol);
   server.setListenAddresses(address);
   return server;
 }