Java Code Examples for com.icegreen.greenmail.util.GreenMailUtil#getSession()

The following examples show how to use com.icegreen.greenmail.util.GreenMailUtil#getSession() . 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: EMailTestServer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public void deliverMultipartMessage(String user, String password, String from, String subject,
                                                                   String contentType, Object body) throws Exception {
    GreenMailUser greenUser = greenMail.setUser(user, password);
    MimeMultipart multiPart = new MimeMultipart();
    MimeBodyPart textPart = new MimeBodyPart();
    multiPart.addBodyPart(textPart);
    textPart.setContent(body, contentType);

    Session session = GreenMailUtil.getSession(server.getServerSetup());
    MimeMessage mimeMessage = new MimeMessage(session);
    mimeMessage.setRecipients(Message.RecipientType.TO, greenUser.getEmail());
    mimeMessage.setFrom(from);
    mimeMessage.setSubject(subject);
    mimeMessage.setContent(multiPart, "multipart/mixed");
    greenUser.deliver(mimeMessage);
}
 
Example 2
Source File: SmtpServerTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@Test
public void testSmtpServerReceiveWithAUTHSuffix() throws Throwable {
    assertEquals(0, greenMail.getReceivedMessages().length);

    String subject = GreenMailUtil.random();

    Properties mailProps = new Properties();
    mailProps.setProperty("mail.smtp.from", "<[email protected]> AUTH <somethingidontknow>");
    Session session = GreenMailUtil.getSession(ServerSetupTest.SMTP, mailProps);

    MimeMessage message = new MimeMessage(session);
    message.setContent("body1", "text/plain");
    message.setFrom("from@localhost");
    message.setRecipients(RecipientType.TO, InternetAddress.parse("to@localhost"));
    message.setSubject(subject);

    GreenMailUtil.sendMimeMessage(message);
    System.setProperty("mail.smtp.from", "<[email protected]> AUTH <somethingidontknow>");
    

    greenMail.waitForIncomingEmail(1500, 1);
    MimeMessage[] emails = greenMail.getReceivedMessages();
    assertEquals(1, emails.length);
    assertEquals(subject, emails[0].getSubject());
}
 
Example 3
Source File: SendReceiveWithInternationalAddressTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@Test
public void testSend() throws MessagingException, UnsupportedEncodingException {

    Session session = GreenMailUtil.getSession(ServerSetupTest.SMTP, properties);
    MimeMessage mimeMessage = new MockInternationalizedMimeMessage(session);
    mimeMessage.setSubject("subject");
    mimeMessage.setSentDate(new Date());
    mimeMessage.setFrom("múchätįldé@tìldę.oœ");
    mimeMessage.setRecipients(Message.RecipientType.TO, "用户@例子.广告");
    mimeMessage.setRecipients(Message.RecipientType.CC, "θσερεχα@μπλε.ψομ");
    mimeMessage.setRecipients(Message.RecipientType.BCC, "राममो@हन.ईन्फो");

    // The body text needs to be encoded if it contains non us-ascii characters
    mimeMessage.setText(MimeUtility.encodeText("用户@例子"));

    GreenMailUtil.sendMimeMessage(mimeMessage);

    // Decoding the body text to verify equality
    String decodedText = MimeUtility.decodeText(GreenMailUtil.getBody(greenMail.getReceivedMessages()[0]));
    assertEquals("用户@例子", decodedText);
}