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


Java MimeMessage.getAllRecipients方法代碼示例

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


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

示例1: transformAndSend

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
protected void transformAndSend(InputStream template, Map<String, Object> arguments, MimeMessageHelper helper)
        throws MessagingException, IOException {

    if (!enabled) {
        log.warn("Mail message was silently consumed because mail system is disabled.");
        return;
    }

    String text = templater.transform(template, arguments);
    helper.setText(text, true);

    MimeMessage message = helper.getMimeMessage();

    if (message.getAllRecipients() != null && message.getAllRecipients().length > 0) {
        sender.send(message);
    } else {
        log.warn("Mail message was silently consumed because there were no recipients.");
    }
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:20,代碼來源:MailCenter.java

示例2: register

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
@Test
public void register() throws Exception {
    mockMvc.perform(
            post(URL_REGISTRATION)
                    .contentType(MediaType.APPLICATION_JSON)
                    .content(asJsonString(new RequestUserDTO(USERNAME, EMAIL_TO, ""))))
            .andExpect(status().isOk());

    MimeMessage[] receivedMessages = testSmtp.getReceivedMessages();
    assertEquals(1, receivedMessages.length);
    MimeMessage message = receivedMessages[0];
    assertEquals(EmailSenderImpl.SUBJECT, message.getSubject());
    String body = GreenMailUtil.getBody(message).replaceAll("=\r?\n", "");
    Address to = message.getAllRecipients()[0];
    Address from = message.getFrom()[0];
    assertEquals(EMAIL_TO, to.toString());
    assertEquals(EmailSenderImpl.EMAIL_FROM, from.toString());
    String url = TestUtils.extractLink(body);
    mockMvc.perform(get(url))
            .andExpect(status().isOk());

}
 
開發者ID:egch,項目名稱:sushi-bar-BE,代碼行數:23,代碼來源:RegistrationControllerTest.java

示例3: 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

示例4: testSendingToUserWithMailAlikeName

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
/**
 * Test for MNT-11079
 */
@Test
public void testSendingToUserWithMailAlikeName() throws IOException, MessagingException
{
    final String USER_1 = "[email protected]";
    final String USER_1_EMAIL = "[email protected]";

    try
    {
        createUser(USER_1, USER_1_EMAIL);

        Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME);
        mailAction.setParameterValue(MailActionExecuter.PARAM_FROM, "[email protected]");
        mailAction.setParameterValue(MailActionExecuter.PARAM_TO_MANY, USER_1);

        mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing");
        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);
        Assert.assertEquals("Hello Jan 1, 1970", (String) message.getContent());
        Assert.assertEquals(1, message.getAllRecipients().length);
        javax.mail.internet.InternetAddress address = (InternetAddress) message.getAllRecipients()[0];
        Assert.assertEquals(USER_1_EMAIL, address.getAddress());
    }
    finally
    {
        // tidy up
        PERSON_SERVICE.deletePerson(USER_1);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:38,代碼來源:AbstractMailActionExecuterTest.java

示例5: 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

示例6: 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

示例7: buildMimeMessage

import javax.mail.internet.MimeMessage; //導入方法依賴的package包/類
private MimeMessage buildMimeMessage() throws Exception {
    if (StringUtils.isBlank(step.subject) || StringUtils.isBlank(step.body)) {
        throw new AbortException("Email not sent. All mandatory properties must be supplied ('subject', 'body').");
    }

    MimeMessageBuilder messageBuilder = new MimeMessageBuilder().setListener(getContext().get(TaskListener.class));

    if (step.subject != null) {
        messageBuilder.setSubject(step.subject);
    }
    if (step.body != null) {
        messageBuilder.setBody(step.body);
    }
    if (step.from != null) {
        messageBuilder.setFrom(step.from);
    }
    if (step.replyTo != null) {
        messageBuilder.setReplyTo(step.replyTo);
    }
    if (step.to != null) {
        messageBuilder.addRecipients(step.to, Message.RecipientType.TO);
    }
    if (step.cc != null) {
        messageBuilder.addRecipients(step.cc, Message.RecipientType.CC);
    }
    if (step.bcc != null) {
        messageBuilder.addRecipients(step.bcc, Message.RecipientType.BCC);
    }
    if (step.charset != null) {
        messageBuilder.setCharset(step.charset);
    }
    if (step.mimeType != null) {
        messageBuilder.setMimeType(step.mimeType);
    }

    MimeMessage message = messageBuilder.buildMimeMessage();

    Address[] allRecipients = message.getAllRecipients();
    if (allRecipients == null || allRecipients.length == 0) {
        throw new AbortException("Email not sent. No recipients of any kind specified ('to', 'cc', 'bcc').");
    }

    return message;
}
 
開發者ID:10000TB,項目名稱:Jenkins-Plugin-Examples,代碼行數:45,代碼來源:MailStep.java


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