當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeMessage.getRecipients方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeMessage.getRecipients方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMessage.getRecipients方法的具體用法?Java MimeMessage.getRecipients怎麽用?Java MimeMessage.getRecipients使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeMessage的用法示例。


在下文中一共展示了MimeMessage.getRecipients方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSendingToCarbonCopy

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * Test for CC / BCC 
 * @throws Exception 
 */
@Test
public void testSendingToCarbonCopy() throws IOException, MessagingException
{
    // PARAM_TO variant
    Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
    mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
    mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "[email protected]");
    mailAction.setParameterValue(MailActionExecuter.PARAM_CC, "[email protected]");
    mailAction.setParameterValue(MailActionExecuter.PARAM_BCC, "[email protected]");

    mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing CARBON COPY");
    mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, "alfresco/templates/mail/test.txt.ftl");

    mailAction.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) getModel());

    ACTION_SERVICE.executeAction(mailAction, null);

    MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
    Assert.assertNotNull(message);
    Address[] all = message.getAllRecipients();
    Address[] ccs = message.getRecipients(RecipientType.CC);
    Address[] bccs = message.getRecipients(RecipientType.BCC);
    Assert.assertEquals(3, all.length);
    Assert.assertEquals(1, ccs.length);
    Assert.assertEquals(1, bccs.length);
    Assert.assertTrue(ccs[0].toString().contains("some.carbon"));
    Assert.assertTrue(bccs[0].toString().contains("some.blindcarbon"));
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:33,代碼來源:AbstractMailActionExecuterTest.java

示例2: testSendingToArrayOfCarbonCopyAndBlindCarbonCopyUsers

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * ALF-21948
 */
@Test
public void testSendingToArrayOfCarbonCopyAndBlindCarbonCopyUsers() throws MessagingException
{
    Map<String, Serializable> params = new HashMap<String, Serializable>();
    String[] ccArray = { "[email protected]", "[email protected]" };
    String[] bccArray = { "[email protected]", "[email protected]", "[email protected]" };
    params.put(MailActionExecuter.PARAM_FROM, "[email protected]");
    params.put(MailActionExecuter.PARAM_TO, "[email protected]");
    params.put(MailActionExecuter.PARAM_CC, ccArray);
    params.put(MailActionExecuter.PARAM_BCC, bccArray);

    params.put(MailActionExecuter.PARAM_TEXT, "Mail body here");
    params.put(MailActionExecuter.PARAM_SUBJECT, "Subject text");

    Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME, params);
    ACTION_EXECUTER.resetTestSentCount();

    ACTION_SERVICE.executeAction(mailAction, null);
    MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
    Assert.assertNotNull(message);

    Address[] all = message.getAllRecipients();
    Address[] ccs = message.getRecipients(RecipientType.CC);
    Address[] bccs = message.getRecipients(RecipientType.BCC);
    Assert.assertEquals(6, all.length);
    Assert.assertEquals(2, ccs.length);
    Assert.assertEquals(3, bccs.length);
    Assert.assertTrue(ccs[0].toString().contains("cc_user1") && ccs[1].toString().contains("cc_user2"));
    Assert.assertTrue(bccs[0].toString().contains("bcc_user3") && bccs[1].toString().contains("bcc_user4")
                      && bccs[2].toString().contains("bcc_user5"));
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:35,代碼來源:AbstractMailActionExecuterTest.java

示例3: testSendingToListOfCarbonCopyAndBlindCarbonCopyUsers

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * ALF-21948
 */
@Test
public void testSendingToListOfCarbonCopyAndBlindCarbonCopyUsers() throws MessagingException
{
    List<String> ccList = new ArrayList<String>();
    ccList.add("[email protected]");
    ccList.add("[email protected]");

    List<String> bccList = new ArrayList<String>();
    bccList.add("[email protected]");
    bccList.add("[email protected]");
    bccList.add("[email protected]");

    Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
    mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
    mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "[email protected]");
    mailAction.setParameterValue(MailActionExecuter.PARAM_CC, (Serializable) ccList);
    mailAction.setParameterValue(MailActionExecuter.PARAM_BCC, (Serializable) bccList);

    mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing (BLIND) CARBON COPY");
    mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "mail body here");

    ACTION_EXECUTER.resetTestSentCount();
    ACTION_SERVICE.executeAction(mailAction, null);
    MimeMessage message = ACTION_EXECUTER.retrieveLastTestMessage();
    Assert.assertNotNull(message);

    Address[] all = message.getAllRecipients();
    Address[] ccs = message.getRecipients(RecipientType.CC);
    Address[] bccs = message.getRecipients(RecipientType.BCC);
    Assert.assertEquals(6, all.length);
    Assert.assertEquals(2, ccs.length);
    Assert.assertEquals(3, bccs.length);
    Assert.assertTrue(ccs[0].toString().contains("cc_user1") && ccs[1].toString().contains("cc_user2"));
    Assert.assertTrue(bccs[0].toString().contains("bcc_user3") && bccs[1].toString().contains("bcc_user4")
                      && bccs[2].toString().contains("bcc_user5"));
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:40,代碼來源:AbstractMailActionExecuterTest.java

示例4: testPrepareEmailForDisabledUsers

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Test
public void testPrepareEmailForDisabledUsers() throws MessagingException
{
    String groupName = null;
    final String USER1 = "test_user1";
    final String USER2 = "test_user2";
    try
    {
        createUser(USER1, null);
        NodeRef userNode = createUser(USER2, null);
        groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1");
        AUTHORITY_SERVICE.addAuthority(groupName, USER1);
        AUTHORITY_SERVICE.addAuthority(groupName, USER2);
        NODE_SERVICE.addAspect(userNode, ContentModel.ASPECT_PERSON_DISABLED, null);
        final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
        mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
        mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, groupName);

        mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
        mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "Testing");

        RetryingTransactionHelper txHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);

        MimeMessage mm = txHelper.doInTransaction(new RetryingTransactionCallback<MimeMessage>()
        {
            @Override
            public MimeMessage execute() throws Throwable
            {
                return ACTION_EXECUTER.prepareEmail(mailAction, null, null, null).getMimeMessage();
            }
        }, true);

        Address[] addresses = mm.getRecipients(Message.RecipientType.TO);
        Assert.assertEquals(1, addresses.length);
        Assert.assertEquals(USER1 + "@email.com", addresses[0].toString());
    }
    finally
    {
        if (groupName != null)
        {
            AUTHORITY_SERVICE.deleteAuthority(groupName, true);
        }
        PERSON_SERVICE.deletePerson(USER1);
        PERSON_SERVICE.deletePerson(USER2);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:47,代碼來源:AbstractMailActionExecuterTest.java


注:本文中的javax.mail.internet.MimeMessage.getRecipients方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。