org.subethamail.smtp.client.SMTPException Java Examples

The following examples show how to use org.subethamail.smtp.client.SMTPException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MailToHostTransmitterTest.java    From mireka with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendAllAddressRejected() throws IllegalArgumentException,
        SendException, SMTPException, IOException, PostponeException {
    new NonStrictExpectations() {
        {
            client.to(anyString);
            result = SMTP_EXCEPTION;

        }
    };

    try {
        sender.transmit(mail, client);
        fail("Exception must have been thrown");
    } catch (RecipientsWereRejectedException e) {
        assertEquals(e.rejections.size(), 1);
        assertEquals(e.rejections.get(0).recipient, JANE_AS_RECIPIENT);
    }

    new Verifications() {
        {
            client.dataStart();
            times = 0;
        }
    };
}
 
Example #2
Source File: MailToHostTransmitterTest.java    From mireka with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendIoExceptionIsTransient() throws SMTPException,
        IOException, RecipientsWereRejectedException, PostponeException {
    new NonStrictExpectations() {
        {
            client.to(anyString);
            result = new IOException();
        }
    };

    try {
        sender.transmit(mail, client);
        fail("Exception must have been thrown");
    } catch (SendException e) {
        assertTrue(e.errorStatus().shouldRetry());
    }

}
 
Example #3
Source File: MailToHostTransmitterTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
@Test
public void testSendFirstAddressRejectedFromTwo()
        throws IllegalArgumentException, SendException, SMTPException,
        IOException, PostponeException {

    new NonStrictExpectations() {
        {
            client.to(anyString);
            result = SMTP_EXCEPTION;
            result = null;
        }
    };

    try {
        mail.recipients =
                Arrays.asList(JANE_AS_RECIPIENT, JOHN_AS_RECIPIENT);
        sender.transmit(mail, client);
        fail("Exception must have been thrown");
    } catch (RecipientsWereRejectedException e) {
        assertEquals(1, e.rejections.size());
        assertEquals(JANE_AS_RECIPIENT, e.rejections.get(0).recipient);
    }

    new Verifications() {
        {
            client.dataStart();
        }
    };
}
 
Example #4
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testEmptyReturnPath() throws Exception {
    // Here there isn't a good email in the from address to make a return path
    String reference = "/mailarchive/empty-return-path/main";
    SmartClient client = createClient();
    client.from("");
}
 
Example #5
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testNoReturnPath() throws Exception {
    // Here there isn't a good email in the from address to make a return path
    String reference = "/mailarchive/no-good-mail/main";
    SmartClient client = createClient();
    client.from("");
}
 
Example #6
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testNoPermission() throws Exception {
    // Here there is no permission, this should never happen in real life
    String reference = "/mailarchive/no-permission/main";
    when(mailArchiveService.channelReference("no-permission", SiteService.MAIN_CONTAINER)).thenReturn(reference);
    when(mailArchiveService.getMailArchiveChannel(reference)).thenThrow(PermissionException.class);
    SmartClient client = createClient();
    client.from("[email protected]");
    client.to("[email protected]");
    writeData(client, "/no-permission.txt");
}
 
Example #7
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testRejectedAddress() throws Exception {
    when(aliasService.getTarget("user")).thenThrow(IdUnusedException.class);
    when(rb.getString("err_addr_unknown")).thenReturn("err_addr_unknown");
    SmartClient client = createClient();
    client.from("[email protected]");
    client.to("[email protected]");
}
 
Example #8
Source File: ClientServerRelayTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
@Test
public void testReceivingAndSending() throws IOException, SMTPException,
        IOException {
    SmartClient client = new SmartClient("localhost", 8025, "SmartClient");
    client.from("[email protected]");
    client.to("[email protected]");
    client.dataStart();
    byte[] exampleMail = ExampleMailData.simple().bytes;
    client.dataWrite(exampleMail, exampleMail.length);
    client.dataEnd();
    client.quit();

    WiserMessage message = wiser.getMessages().get(0);
    assertThat(message.getData(), new ArrayEndsWith(exampleMail));
}
 
Example #9
Source File: MxPopTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
private void sendMail() throws UnknownHostException, IOException,
        SMTPException {
    SmartClient client =
            new SmartClient("localhost", PORT_SMTP, "SmartClient");
    client.from("[email protected]");
    client.to("[email protected]");
    client.dataStart();
    byte[] exampleMail = ExampleMailData.simple().bytes;
    client.dataWrite(exampleMail, exampleMail.length);
    client.dataEnd();
    client.quit();
}
 
Example #10
Source File: MxPopTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
@Test
public void testReceiveRetrieve() throws IOException, SMTPException,
        MessagingException {

    sendMail();

    retrieveMail();
}
 
Example #11
Source File: MailToHostTransmitterTest.java    From mireka with Apache License 2.0 5 votes vote down vote up
@Test(expected = RemoteMtaErrorResponseException.class)
public void testSendSmtpErrorResponse() throws SMTPException, IOException,
        RecipientsWereRejectedException, SendException, PostponeException {
    new NonStrictExpectations() {
        {
            client.dataEnd();
            result = SMTP_EXCEPTION;
        }
    };

    sender.transmit(mail, client);
}
 
Example #12
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testEmptyReturnPath() throws Exception {
    // Here there isn't a good email in the from address to make a return path
    String reference = "/mailarchive/empty-return-path/main";
    SmartClient client = createClient();
    client.from("");
}
 
Example #13
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testNoReturnPath() throws Exception {
    // Here there isn't a good email in the from address to make a return path
    String reference = "/mailarchive/no-good-mail/main";
    SmartClient client = createClient();
    client.from("");
}
 
Example #14
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testNoPermission() throws Exception {
    // Here there is no permission, this should never happen in real life
    String reference = "/mailarchive/no-permission/main";
    when(mailArchiveService.channelReference("no-permission", SiteService.MAIN_CONTAINER)).thenReturn(reference);
    when(mailArchiveService.getMailArchiveChannel(reference)).thenThrow(PermissionException.class);
    SmartClient client = createClient();
    client.from("[email protected]");
    client.to("[email protected]");
    writeData(client, "/no-permission.txt");
}
 
Example #15
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
@Test(expected = SMTPException.class)
public void testRejectedAddress() throws Exception {
    when(aliasService.getTarget("user")).thenThrow(IdUnusedException.class);
    when(rb.getString("err_addr_unknown")).thenReturn("err_addr_unknown");
    SmartClient client = createClient();
    client.from("[email protected]");
    client.to("[email protected]");
}
 
Example #16
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Test(expected = SMTPException.class)
public void testRejectedDomain() throws IOException {
    SmartClient client = createClient();
    client.from("[email protected]");
    client.to("[email protected]");
}
 
Example #17
Source File: BackendRejectException.java    From mireka with Apache License 2.0 4 votes vote down vote up
public BackendRejectException(SMTPException cause, String comment) {
    super(cause.getResponse().getCode(), cause.getResponse().getMessage()
            + comment);
}
 
Example #18
Source File: RemoteMtaErrorResponseException.java    From mireka with Apache License 2.0 4 votes vote down vote up
private static MailSystemStatus smtpStatusFromResponse(SMTPException e) {
    return new ResponseParser()
            .createResponseLookingForEnhancedStatusCode(e.getResponse());
}
 
Example #19
Source File: RemoteMtaErrorResponseException.java    From mireka with Apache License 2.0 4 votes vote down vote up
public RemoteMtaErrorResponseException(SMTPException e, MtaAddress remoteMta) {
    super(e, enhancedStatusFromRemoteResponse(smtpStatusFromResponse(e)));
    this.remoteMta = remoteMta;
    this.remoteMtaStatus = smtpStatusFromResponse(e);
}
 
Example #20
Source File: SmtpClient.java    From mireka with Apache License 2.0 4 votes vote down vote up
public void connect() throws SMTPException, IOException {
	super.setHostPort(mtaAddress.toString());
    super.connect(mtaAddress.address.getHostAddress(), mtaAddress.port);
}
 
Example #21
Source File: SakaiMessageHandlerTest.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
@Test(expected = SMTPException.class)
public void testRejectedDomain() throws IOException {
    SmartClient client = createClient();
    client.from("[email protected]");
    client.to("[email protected]");
}