Example usage for javax.mail Message getRecipients

List of usage examples for javax.mail Message getRecipients

Introduction

In this page you can find the example usage for javax.mail Message getRecipients.

Prototype

public abstract Address[] getRecipients(RecipientType type) throws MessagingException;

Source Link

Document

Get all the recipient addresses of the given type.

Usage

From source file:org.jasig.portlet.emailpreview.dao.javamail.JavamailAccountDaoImpl.java

private String getCc(Message message) throws MessagingException {
    Address[] ccRecipients = message.getRecipients(RecipientType.CC);
    return getFormattedAddresses(ccRecipients);
}

From source file:org.jasig.portlet.emailpreview.dao.javamail.JavamailAccountDaoImpl.java

private String getBcc(Message message) throws MessagingException {
    Address[] bccRecipients = message.getRecipients(RecipientType.BCC);
    return getFormattedAddresses(bccRecipients);
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulateWelcomeMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateMessage = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class,
            String.class, Session.class);

    populateMessage.setAccessible(true);

    Message message = (Message) populateMessage.invoke(_classInstance, "user@test.com", "Welcome",
            "welcome_email.vm", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertEquals("Welcome", message.getSubject());
    Assert.assertEquals(_WELCOME_EMAIL, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulatePaymentFailedMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateMessage = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class,
            String.class, Session.class);

    populateMessage.setAccessible(true);

    Message message = (Message) populateMessage.invoke(_classInstance, "user@test.com", "Payment Failed",
            "payment_failed_email.vm", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertEquals("Payment Failed", message.getSubject());
    Assert.assertEquals(_PAYMENT_FAILED_EMAIL, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulateCardDetailsMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateMessage = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class,
            String.class, Session.class);

    populateMessage.setAccessible(true);

    Message message = (Message) populateMessage.invoke(_classInstance, "user@test.com", "Card Details Updated",
            "card_details_email.vm", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertEquals("Card Details Updated", message.getSubject());
    Assert.assertEquals(_CARD_DETAILS_EMAIL, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulateResubscribeMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateMessage = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class,
            String.class, Session.class);

    populateMessage.setAccessible(true);

    Message message = (Message) populateMessage.invoke(_classInstance, "user@test.com",
            "Resubscribe Successful", "resubscribe_email.vm", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertEquals("Resubscribe Successful", message.getSubject());
    Assert.assertEquals(_RESUBSCRIBE_EMAIL, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulateCancellationMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateMessage = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class,
            String.class, Session.class);

    populateMessage.setAccessible(true);

    Message message = (Message) populateMessage.invoke(_classInstance, "user@test.com",
            "Cancellation Successful", "cancellation_email.vm", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertEquals("Cancellation Successful", message.getSubject());
    Assert.assertEquals(_CANCELLATION_EMAIL, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulateEmailMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateEmailMessageMethod = _clazz.getDeclaredMethod("_populateEmailMessage", Map.class,
            String.class, String.class, Session.class);

    populateEmailMessageMethod.setAccessible(true);

    List<SearchResult> searchResults = new ArrayList<>();

    SearchQuery searchQuery = new SearchQuery(1, _USER_ID, "Test keywords");

    SearchResult searchResult = new SearchResult(1, "1234", "itemTitle", "$14.99", "$29.99",
            "http://www.ebay.com/itm/1234", "http://www.ebay.com/123.jpg");

    searchResults.add(searchResult);/*from   w  w  w . j  a  va  2 s .  com*/

    Map<SearchQuery, List<SearchResult>> searchQueryResultMap = new HashMap<>();

    searchQueryResultMap.put(searchQuery, searchResults);

    Message message = (Message) populateEmailMessageMethod.invoke(_classInstance, searchQueryResultMap,
            "user@test.com", "unsubscribeToken", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertTrue(message.getSubject().contains("New Search Results - "));
    Assert.assertEquals(_EMAIL_CONTENT, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.app.test.mail.DefaultMailSenderTest.java

@Test
public void testPopulateAccountDeletionMessage() throws Exception {
    _initializeVelocityTemplate(_clazz, _classInstance);

    Method populateMessage = _clazz.getDeclaredMethod("_populateMessage", String.class, String.class,
            String.class, Session.class);

    populateMessage.setAccessible(true);

    Message message = (Message) populateMessage.invoke(_classInstance, "user@test.com",
            "Account Deletion Successful", "account_deletion_email.vm", _session);

    Assert.assertEquals("Auction Alert <test@test.com>", message.getFrom()[0].toString());
    Assert.assertEquals("Account Deletion Successful", message.getSubject());
    Assert.assertEquals(_ACCOUNT_DELETION_EMAIL, message.getContent());

    InternetAddress[] internetAddresses = new InternetAddress[1];

    internetAddresses[0] = new InternetAddress("user@test.com");

    Assert.assertArrayEquals(internetAddresses, message.getRecipients(Message.RecipientType.TO));
}

From source file:com.duroty.utils.mail.MessageUtilities.java

/**
 * Decode recipent addresses of the message into UTF strings. This is a
 * convenience method provided to simplify application code.
 *
 * @param message The message to interogate
 * @param type The type of message recipients to decode, i.e. from, to, cc,
 *        etc//from   w w w  . j av a2  s  .c o m
 *
 * @return String List of decoded addresses
 *
 * @exception MessagingException if the message contents are invalid
 */
public static String decodeAddresses(Message message, Message.RecipientType type)
        throws MessagingException, Exception {
    Address[] xaddresses = message.getRecipients(type);

    return decodeAddresses(xaddresses);
}