本文整理汇总了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.");
}
}
示例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());
}
示例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"));
}
示例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);
}
}
示例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"));
}
示例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"));
}
示例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;
}