Example usage for javax.mail Message getSubject

List of usage examples for javax.mail Message getSubject

Introduction

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

Prototype

public abstract String getSubject() throws MessagingException;

Source Link

Document

Get the subject of this message.

Usage

From source file:org.apache.usergrid.rest.management.RegistrationIT.java

@Test
public void postCreateOrgAndAdmin() throws Exception {

    Map<String, String> originalProperties = getRemoteTestProperties();

    try {//from  www  . j  av a2  s.  c o  m
        setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
        setTestProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
        setTestProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "false");
        setTestProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");

        JsonNode node = postCreateOrgAndAdmin("test-org-1", "test-user-1", "Test User",
                "test-user-1@mockserver.com", "testpassword");

        UUID owner_uuid = UUID
                .fromString(node.findPath("data").findPath("owner").findPath("uuid").getTextValue());

        List<Message> inbox = org.jvnet.mock_javamail.Mailbox.get("test-user-1@mockserver.com");

        assertFalse(inbox.isEmpty());

        Message account_confirmation_message = inbox.get(0);
        assertEquals("User Account Confirmation: test-user-1@mockserver.com",
                account_confirmation_message.getSubject());

        String token = getTokenFromMessage(account_confirmation_message);
        logger.info(token);

        setup.getMgmtSvc().disableAdminUser(owner_uuid);
        try {
            resource().path("/management/token").queryParam("grant_type", "password")
                    .queryParam("username", "test-user-1").queryParam("password", "testpassword")
                    .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON_TYPE)
                    .get(JsonNode.class);
            fail("request for disabled user should fail");
        } catch (UniformInterfaceException uie) {
            ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
            JsonNode body = uie.getResponse().getEntity(JsonNode.class);
            assertEquals("user disabled", body.findPath("error_description").getTextValue());
        }

        setup.getMgmtSvc().deactivateUser(CassandraService.MANAGEMENT_APPLICATION_ID, owner_uuid);
        try {
            resource().path("/management/token").queryParam("grant_type", "password")
                    .queryParam("username", "test-user-1").queryParam("password", "testpassword")
                    .accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON_TYPE)
                    .get(JsonNode.class);
            fail("request for deactivated user should fail");
        } catch (UniformInterfaceException uie) {
            ClientResponse.Status status = uie.getResponse().getClientResponseStatus();
            JsonNode body = uie.getResponse().getEntity(JsonNode.class);
            assertEquals("user not activated", body.findPath("error_description").getTextValue());
        }

        // assertEquals(ActivationState.ACTIVATED,
        // svcSetup.getMgmtSvc().handleConfirmationTokenForAdminUser(
        // owner_uuid, token));

        // need to enable JSP usage in the test version of Jetty to make this test run
        //      String response = resource()
        //        .path("/management/users/" + owner_uuid + "/confirm").get(String.class);
        //      logger.info(response);
        //      Message account_activation_message = inbox.get(1);
        //      assertEquals("User Account Activated", account_activation_message.getSubject());

    } finally {
        setTestProperties(originalProperties);
    }
}

From source file:org.openiam.idm.srvc.msg.service.MailSender.java

public void send(Message msg) {
    Properties properties = System.getProperties();
    properties.setProperty("mail.smtp.host", host);
    Session session = Session.getDefaultInstance(properties);
    MimeMessage message = new MimeMessage(session);
    try {//from   w w  w  .j a  va  2 s. c  o  m
        message.setFrom(msg.getFrom());
        message.addRecipient(javax.mail.Message.RecipientType.TO, msg.getTo());
        message.setSubject(msg.getSubject());
        message.setText(msg.getBody());

        Transport.send(message);
        log.info("Message successfully sent.");
    } catch (MessagingException me) {
        log.error(me);
        me.printStackTrace();
    }
}

From source file:org.apache.usergrid.management.EmailFlowIT.java

@Test
public void testCreateOrganizationAndAdminWithConfirmationOnly() throws Exception {
    setup.set(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "false");
    setup.set(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    setup.set(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true");
    setup.set(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-1@mockserver.com");
    setup.set(PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true");

    OrganizationOwnerInfo org_owner = createOwnerAndOrganization(ORGANIZATION_NAME, "test-user-1", "Test User",
            "test-user-1@mockserver.com", "testpassword", false, false);
    assertNotNull(org_owner);//from   w ww.  ja v  a2 s. c  om

    List<Message> inbox = Mailbox.get("test-user-1@mockserver.com");

    assertFalse(inbox.isEmpty());

    MockImapClient client = new MockImapClient("mockserver.com", "test-user-1", "somepassword");
    client.processMail();

    Message confirmation = inbox.get(0);
    assertEquals("User Account Confirmation: test-user-1@mockserver.com", confirmation.getSubject());

    String token = getTokenFromMessage(confirmation);
    LOG.info(token);

    assertEquals(ActivationState.ACTIVATED,
            setup.getMgmtSvc().handleConfirmationTokenForAdminUser(org_owner.owner.getUuid(), token));

    Message activation = inbox.get(1);
    assertEquals("User Account Activated", activation.getSubject());

    client = new MockImapClient("mockserver.com", "test-user-1", "somepassword");
    client.processMail();
}

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

@Test
public void testPopulateContactMessage() throws Exception {
    Method populateContactMessage = _clazz.getDeclaredMethod("_populateContactMessage", String.class,
            String.class, Session.class);

    populateContactMessage.setAccessible(true);

    Message message = (Message) populateContactMessage.invoke(_classInstance, "user@test.com",
            "Sample contact message", _session);

    Assert.assertEquals("user@test.com", message.getFrom()[0].toString());
    Assert.assertEquals("You Have A New Message From user@test.com", message.getSubject());
    Assert.assertEquals("Sample contact message", message.getContent());
}

From source file:org.usergrid.management.EmailFlowIT.java

@Test
public void testCreateOrganizationAndAdminWithConfirmationAndActivation() throws Exception {
    setup.set(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "true");
    setup.set(PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true");
    setup.set(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    setup.set(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true");
    setup.set(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-2@mockserver.com");

    OrganizationOwnerInfo org_owner = createOwnerAndOrganization(ORGANIZATION_NAME_2, "test-user-2",
            "Test User", "test-user-2@mockserver.com", "testpassword", false, false);
    assertNotNull(org_owner);// w  w w  . jav a2s .  c  om

    List<Message> user_inbox = Mailbox.get("test-user-2@mockserver.com");

    assertFalse(user_inbox.isEmpty());

    Message confirmation = user_inbox.get(0);
    assertEquals("User Account Confirmation: test-user-2@mockserver.com", confirmation.getSubject());

    String token = getTokenFromMessage(confirmation);
    LOG.info(token);

    ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser(org_owner.owner.getUuid(),
            token);
    assertEquals(ActivationState.CONFIRMED_AWAITING_ACTIVATION, state);

    confirmation = user_inbox.get(1);
    assertEquals("User Account Confirmed", confirmation.getSubject());

    List<Message> sysadmin_inbox = Mailbox.get("sysadmin-2@mockserver.com");
    assertFalse(sysadmin_inbox.isEmpty());

    Message activation = sysadmin_inbox.get(0);
    assertEquals("Request For Admin User Account Activation test-user-2@mockserver.com",
            activation.getSubject());

    token = getTokenFromMessage(activation);
    LOG.info(token);

    state = setup.getMgmtSvc().handleActivationTokenForAdminUser(org_owner.owner.getUuid(), token);
    assertEquals(ActivationState.ACTIVATED, state);

    Message activated = user_inbox.get(2);
    assertEquals("User Account Activated", activated.getSubject());

    MockImapClient client = new MockImapClient("mockserver.com", "test-user-2", "somepassword");
    client.processMail();
}

From source file:org.usergrid.management.EmailFlowTest.java

@Test
public void testCreateOrganizationAndAdminWithConfirmationAndActivation() throws Exception {

    properties.setProperty(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "true");
    properties.setProperty(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    properties.setProperty(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true");
    properties.setProperty(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-2@mockserver.com");

    OrganizationOwnerInfo org_owner = management.createOwnerAndOrganization(ORGANIZATION_NAME_2, "test-user-2",
            "Test User", "test-user-2@mockserver.com", "testpassword", false, false);
    assertNotNull(org_owner);//from ww w.j  a  v a2  s .c  om

    List<Message> user_inbox = org.jvnet.mock_javamail.Mailbox.get("test-user-2@mockserver.com");

    assertFalse(user_inbox.isEmpty());

    Message account_confirmation_message = user_inbox.get(0);
    assertEquals("User Account Confirmation: test-user-2@mockserver.com",
            account_confirmation_message.getSubject());

    String token = getTokenFromMessage(account_confirmation_message);
    logger.info(token);

    assertEquals(ActivationState.CONFIRMED_AWAITING_ACTIVATION,
            management.handleConfirmationTokenForAdminUser(org_owner.owner.getUuid(), token));

    Message account_confirmed_message = user_inbox.get(1);
    assertEquals("User Account Confirmed", account_confirmed_message.getSubject());

    List<Message> sysadmin_inbox = org.jvnet.mock_javamail.Mailbox.get("sysadmin-2@mockserver.com");
    assertFalse(sysadmin_inbox.isEmpty());

    Message account_activation_message = sysadmin_inbox.get(0);
    assertEquals("Request For Admin User Account Activation test-user-2@mockserver.com",
            account_activation_message.getSubject());

    token = getTokenFromMessage(account_activation_message);
    logger.info(token);

    assertEquals(ActivationState.ACTIVATED,
            management.handleActivationTokenForAdminUser(org_owner.owner.getUuid(), token));

    Message account_activated_message = user_inbox.get(2);
    assertEquals("User Account Activated", account_activated_message.getSubject());

    MockImapClient client = new MockImapClient("mockserver.com", "test-user-2", "somepassword");
    client.processMail();

}

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 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 .ja  v a  2s  .  c  om*/

    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:org.apache.usergrid.management.EmailFlowIT.java

@Test
public void testCreateOrganizationAndAdminWithConfirmationAndActivation() throws Exception {
    setup.set(PROPERTIES_SYSADMIN_APPROVES_ADMIN_USERS, "true");
    setup.set(PROPERTIES_NOTIFY_ADMIN_OF_ACTIVATION, "true");
    setup.set(PROPERTIES_SYSADMIN_APPROVES_ORGANIZATIONS, "false");
    setup.set(PROPERTIES_ADMIN_USERS_REQUIRE_CONFIRMATION, "true");
    setup.set(PROPERTIES_SYSADMIN_EMAIL, "sysadmin-2@mockserver.com");

    OrganizationOwnerInfo org_owner = createOwnerAndOrganization(ORGANIZATION_NAME_2, "test-user-2",
            "Test User", "test-user-2@mockserver.com", "testpassword", false, false);
    assertNotNull(org_owner);//from  ww w  .  j  av a2 s  .  c o  m

    List<Message> user_inbox = Mailbox.get("test-user-2@mockserver.com");

    assertFalse(user_inbox.isEmpty());

    Message confirmation = user_inbox.get(0);
    assertEquals("User Account Confirmation: test-user-2@mockserver.com", confirmation.getSubject());

    String token = getTokenFromMessage(confirmation);
    LOG.info(token);

    ActivationState state = setup.getMgmtSvc().handleConfirmationTokenForAdminUser(org_owner.owner.getUuid(),
            token);
    assertEquals(ActivationState.CONFIRMED_AWAITING_ACTIVATION, state);

    confirmation = user_inbox.get(1);
    String body = ((MimeMultipart) confirmation.getContent()).getBodyPart(0).getContent().toString();
    Boolean subbedEmailed = StringUtils.contains(body, "$");

    assertFalse(subbedEmailed);

    assertEquals("User Account Confirmed", confirmation.getSubject());

    List<Message> sysadmin_inbox = Mailbox.get("sysadmin-2@mockserver.com");
    assertFalse(sysadmin_inbox.isEmpty());

    Message activation = sysadmin_inbox.get(0);
    assertEquals("Request For Admin User Account Activation test-user-2@mockserver.com",
            activation.getSubject());

    token = getTokenFromMessage(activation);
    LOG.info(token);

    state = setup.getMgmtSvc().handleActivationTokenForAdminUser(org_owner.owner.getUuid(), token);
    assertEquals(ActivationState.ACTIVATED, state);

    Message activated = user_inbox.get(2);
    assertEquals("User Account Activated", activated.getSubject());

    MockImapClient client = new MockImapClient("mockserver.com", "test-user-2", "somepassword");
    client.processMail();
}

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));
}