&& isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.CC)) && isNullOrEmpty((Object[]) m.getRecipients(Message.RecipientType.BCC)) ) { throw new SendFailedException("No recipient addresses"); super.notifyTransportListeners(TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent, invalid.toArray(new Address[invalid.size()]), m); throw new SendFailedException("AWS Mail Service can only send to InternetAddresses");
TransportEvent.MESSAGE_NOT_DELIVERED, sent, unsent, invalid, m); throw new SendFailedException("Unable to send email", e, sent, unsent, invalid);
throw new SendFailedException("No recipient addresses"); throw new SendFailedException("No recipient addresses"); invalid.toArray(c); throw new SendFailedException("Sending failed", chainedEx, a, b, c);
throw new SendFailedException("No recipient addresses"); throw new SendFailedException("No recipient addresses"); invalid.toArray(c); throw new SendFailedException("Sending failed", chainedEx, a, b, c);
throw new SendFailedException("Invalid Addresses", mex, validSentAddr, validUnsentAddr, invalidAddr);
throw new SendFailedException("Invalid Addresses", mex, validSentAddr, validUnsentAddr, invalidAddr);
@Test public void deliverShouldAttemptDeliveryOnlyOnceIfNoMoreValidUnsent() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of( HOST_ADDRESS_1, HOST_ADDRESS_2).iterator(); when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries); when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), any(HostAddress.class))) .thenThrow(new SendFailedException()); ExecutionResult executionResult = testee.deliver(mail); verify(mailDelivrerToHost, times(1)).tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), any(HostAddress.class)); assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE); }
@Test public void deliverShouldAttemptDeliveryOnBothMXIfStillRecipients() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of( HOST_ADDRESS_1, HOST_ADDRESS_2).iterator(); when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries); when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), any(HostAddress.class))) .thenThrow(sfe); ExecutionResult executionResult = testee.deliver(mail); verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), any(HostAddress.class)); assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.TEMPORARY_FAILURE); }
throw new SendFailedException("No recipient addresses");
@Test public void deliverShouldWorkIfOnlyMX2Valid() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); UnmodifiableIterator<HostAddress> dnsEntries = ImmutableList.of( HOST_ADDRESS_1, HOST_ADDRESS_2).iterator(); when(dnsHelper.retrieveHostAddressIterator(MailAddressFixture.JAMES_APACHE_ORG)).thenReturn(dnsEntries); when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), eq(HOST_ADDRESS_1))) .thenThrow(sfe); when(mailDelivrerToHost.tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), eq(HOST_ADDRESS_2))) .thenReturn(ExecutionResult.success()); ExecutionResult executionResult = testee.deliver(mail); verify(mailDelivrerToHost, times(2)).tryDeliveryToHost(any(Mail.class), any(InternetAddress[].class), any(HostAddress.class)); assertThat(executionResult.getExecutionState()).isEqualTo(ExecutionResult.ExecutionState.SUCCESS); }
@Test public void handleSenderFailedExceptionShouldReturnPermanentFailureWhenInvalidAndNotValidUnsent() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {}; Address[] invalid = {new InternetAddress(MailAddressFixture.ANY_AT_JAMES.asString())}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); ExecutionResult executionResult = testee.handleSenderFailedException(mail, sfe); assertThat(executionResult).isEqualTo(ExecutionResult.permanentFailure(sfe)); }
@Test public void handleSenderFailedExceptionShouldReturnTemporaryFailureWhenInvalidAndValidUnsent() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {new InternetAddress(MailAddressFixture.ANY_AT_JAMES.asString())}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); ExecutionResult executionResult = testee.handleSenderFailedException(mail, sfe); assertThat(executionResult).isEqualTo(ExecutionResult.temporaryFailure(sfe)); }
@Test public void handleSenderFailedExceptionShouldReturnTemporaryFailureWhenValidUnsent() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); ExecutionResult executionResult = testee.handleSenderFailedException(mail, sfe); assertThat(executionResult).isEqualTo(ExecutionResult.temporaryFailure(sfe)); }
@Test public void handleSenderFailedExceptionShouldBounceInvalidAddressesOnBothInvalidAndValidUnsent() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {new InternetAddress(MailAddressFixture.ANY_AT_JAMES.asString())}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); testee.handleSenderFailedException(mail, sfe); verify(bouncer).bounce(mail, sfe); verifyNoMoreInteractions(bouncer); }
throw new SendFailedException("No recipient addresses");
@Test public void handleSenderFailedExceptionShouldReturnTemporaryFailureByDefault() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); SendFailedException sfe = new SendFailedException(); ExecutionResult executionResult = testee.handleSenderFailedException(mail, sfe); assertThat(executionResult).isEqualTo(ExecutionResult.temporaryFailure(sfe)); }
@Test public void handleSenderFailedExceptionShouldSetRecipientToInvalidWhenOnlyInvalid() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {}; Address[] invalid = {new InternetAddress(MailAddressFixture.ANY_AT_JAMES.asString())}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); testee.handleSenderFailedException(mail, sfe); assertThat(mail.getRecipients()).containsOnly(MailAddressFixture.ANY_AT_JAMES); }
@Test public void handleSenderFailedExceptionShouldSetRecipientToValidUnsentWhenValidUnsentAndInvalid() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {new InternetAddress(MailAddressFixture.ANY_AT_JAMES.asString())}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); testee.handleSenderFailedException(mail, sfe); assertThat(mail.getRecipients()).containsOnly(MailAddressFixture.OTHER_AT_JAMES); }
@Test public void handleSenderFailedExceptionShouldSetRecipientToValidUnsentWhenOnlyValidUnsent() throws Exception { Mail mail = FakeMail.builder().recipients(MailAddressFixture.ANY_AT_JAMES, MailAddressFixture.OTHER_AT_JAMES).build(); Address[] validSent = {}; Address[] validUnsent = {new InternetAddress(MailAddressFixture.OTHER_AT_JAMES.asString())}; Address[] invalid = {}; SendFailedException sfe = new SendFailedException("Message", new Exception(), validSent, validUnsent, invalid); testee.handleSenderFailedException(mail, sfe); assertThat(mail.getRecipients()).containsOnly(MailAddressFixture.OTHER_AT_JAMES); }
@Test public void bounceShouldCustomizeSendFailedExceptionByDefault() throws Exception { RemoteDeliveryConfiguration configuration = new RemoteDeliveryConfiguration( FakeMailetConfig.builder() .setProperty(RemoteDeliveryConfiguration.DELIVERY_THREADS, "1") .setProperty(RemoteDeliveryConfiguration.HELO_NAME, HELLO_NAME) .build(), mock(DomainList.class)); Bouncer testee = new Bouncer(configuration, mailetContext); Mail mail = FakeMail.builder().state(Mail.DEFAULT) .sender(MailAddressFixture.ANY_AT_JAMES) .build(); String exceptionMessage = "Error from remote server"; testee.bounce(mail, new MessagingException("Exception message", new SendFailedException(exceptionMessage))); FakeMailContext.BouncedMail expected = new FakeMailContext.BouncedMail(FakeMailContext.fromMail(mail), "Hi. This is the James mail server at " + HELLO_NAME + ".\n" + "I'm afraid I wasn't able to deliver your message to the following addresses.\n" + "This is a permanent error; I've given up. Sorry it didn't work out. Below\n" + "I include the list of recipients and the reason why I was unable to deliver\n" + "your message.\n" + "\n" + "Remote mail server told me: " + exceptionMessage + "\n\n", Optional.empty()); assertThat(mailetContext.getSentMails()).isEmpty(); assertThat(mailetContext.getBouncedMails()).containsOnly(expected); }