use of javax.mail.Address in project cuba by cuba-platform.
the class EmailerTest method doTestSeveralRecipients.
private void doTestSeveralRecipients(boolean useFs) throws MessagingException {
emailerConfig.setFileStorageUsed(useFs);
testMailSender.clearBuffer();
String body = "Test Email Body";
// 3 recipients
String recipients = "misha@example.com,kolya@example.com;tanya@example.com;";
EmailInfo myInfo = EmailInfoBuilder.create().setAddresses(recipients).setCaption("Test").setBody(body).build();
List<SendingMessage> messages = emailer.sendEmailAsync(myInfo);
assertEquals(3, messages.size());
assertTrue(testMailSender.isEmpty());
emailer.processQueuedEmails();
Set<String> recipientSet = new HashSet<>();
// check
assertEquals(3, testMailSender.getBufferSize());
for (int i = 0; i < 3; i++) {
MimeMessage msg = testMailSender.fetchSentEmail();
Address[] msgRecipients = msg.getAllRecipients();
assertEquals(1, msgRecipients.length);
recipientSet.add(msgRecipients[0].toString());
}
assertTrue(recipientSet.contains("misha@example.com"));
assertTrue(recipientSet.contains("kolya@example.com"));
assertTrue(recipientSet.contains("tanya@example.com"));
}
use of javax.mail.Address in project alfresco-repository by Alfresco.
the class AbstractMailActionExecuterTest method testSendingToArrayOfCarbonCopyAndBlindCarbonCopyUsers.
/**
* ALF-21948
*/
@Test
public void testSendingToArrayOfCarbonCopyAndBlindCarbonCopyUsers() throws MessagingException {
Map<String, Serializable> params = new HashMap<String, Serializable>();
String[] ccArray = { "cc_user1@example.com", "cc_user2@example.com" };
String[] bccArray = { "bcc_user3@example.com", "bcc_user4@example.com", "bcc_user5@example.com" };
params.put(MailActionExecuter.PARAM_FROM, "sender@email.com");
params.put(MailActionExecuter.PARAM_TO, "test@email.com");
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"));
}
use of javax.mail.Address in project alfresco-repository by Alfresco.
the class AbstractMailActionExecuterTest method testSendingToCarbonCopy.
/**
* 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, "some.body@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_TO, "some.bodyelse@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_CC, "some.carbon@example.com");
mailAction.setParameterValue(MailActionExecuter.PARAM_BCC, "some.blindcarbon@example.com");
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"));
}
use of javax.mail.Address in project alfresco-repository by Alfresco.
the class SubethaEmailMessage method processMimeMessage.
private void processMimeMessage(MimeMessage mimeMessage) {
if (from == null) {
Address[] addresses = null;
try {
addresses = mimeMessage.getFrom();
} catch (MessagingException e) {
throw new EmailMessageException(ERR_EXTRACTING_FROM_ADDRESS, e.getMessage());
}
if (addresses == null || addresses.length == 0) {
// throw new EmailMessageException(ERR_NO_FROM_ADDRESS);
} else {
if (addresses[0] instanceof InternetAddress) {
from = ((InternetAddress) addresses[0]).getAddress();
} else {
from = addresses[0].toString();
}
}
}
if (to == null) {
Address[] addresses = null;
try {
addresses = mimeMessage.getAllRecipients();
} catch (MessagingException e) {
throw new EmailMessageException(ERR_EXTRACTING_TO_ADDRESS, e.getMessage());
}
if (addresses == null || addresses.length == 0) {
// throw new EmailMessageException(ERR_NO_TO_ADDRESS);
} else {
if (addresses[0] instanceof InternetAddress) {
to = ((InternetAddress) addresses[0]).getAddress();
} else {
to = addresses[0].toString();
}
}
}
if (cc == null) {
try {
ArrayList<String> list = new ArrayList<String>();
Address[] cca = mimeMessage.getRecipients(RecipientType.CC);
if (cca != null) {
for (Address a : cca) {
list.add(a.toString());
}
}
cc = list;
} catch (MessagingException e) {
// Do nothing - this is not a show-stopper.
cc = null;
}
}
try {
subject = mimeMessage.getSubject();
// subject = encodeSubject(mimeMessage.getSubject());
} catch (MessagingException e) {
throw new EmailMessageException(ERR_EXTRACTING_SUBJECT, e.getMessage());
}
try {
sentDate = mimeMessage.getSentDate();
} catch (MessagingException e) {
throw new EmailMessageException(ERR_EXTRACTING_SENT_DATE, e.getMessage());
}
if (sentDate == null) {
// Just anti-null stub :)
sentDate = new Date();
}
parseMessagePart(mimeMessage);
attachments = new EmailMessagePart[attachmentList.size()];
attachmentList.toArray(attachments);
attachmentList = null;
}
use of javax.mail.Address in project epadd by ePADD.
the class SearchResult method filterForCorrespondents.
/**
* returns only the docs where the name or email address in the given field matches correspondentsStr in the given field(s).
* correspondentsStr can be or-delimited and specify multiple strings.
*/
public static SearchResult filterForCorrespondents(SearchResult inputSet, String correspondentsStr, boolean checkToField, boolean checkFromField, boolean checkCcField, boolean checkBccField) {
Set<Contact> searchedContacts = new LinkedHashSet<>();
AddressBook ab = inputSet.archive.addressBook;
Set<String> correspondents = Util.splitFieldForOr(correspondentsStr);
for (String s : correspondents) {
// this lookup will normalize, be case-insensitive, etc.
Collection<Contact> contacts = ab.lookupByEmailOrName(s);
if (contacts != null)
searchedContacts.addAll(contacts);
}
// keep on removing those documents from allDocs which do not have any contact that matches ANY of searchedContacts
inputSet.matchedDocs = inputSet.matchedDocs.entrySet().stream().filter(k -> {
EmailDocument ed = (EmailDocument) k.getKey();
Collection<Contact> contactsOfInterest = new LinkedHashSet<>();
if (// add from addresses
checkFromField && ed.from != null)
contactsOfInterest.addAll(Arrays.stream(ed.from).map(address -> ab.lookupByAddress(address)).collect(Collectors.toList()));
if (// add to address
checkToField && ed.to != null)
contactsOfInterest.addAll(Arrays.stream(ed.to).map(address -> ab.lookupByAddress(address)).collect(Collectors.toList()));
if (// add ccd addresses
checkCcField && ed.cc != null)
contactsOfInterest.addAll(Arrays.stream(ed.cc).map(address -> ab.lookupByAddress(address)).collect(Collectors.toList()));
if (// add bcc address
checkToField & ed.bcc != null)
contactsOfInterest.addAll(Arrays.stream(ed.bcc).map(address -> ab.lookupByAddress(address)).collect(Collectors.toList()));
// Collection<Contact> contactsInMessage = EmailUtils.getContactsForMessage(ab, ed);
return contactsOfInterest.stream().anyMatch(searchedContacts::contains);
}).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
return inputSet;
}
Aggregations