Esempio n. 1
0
 @Test
 public void testSendEmailMessage() throws Exception {
   // create message with from, subject, content
   EmailMessage msg = new EmailMessage(from.getAddress(), subject + " with attachments", content);
   // add message recipients that appear in the header
   HashMap<RecipientType, List<EmailAddress>> tos =
       new HashMap<RecipientType, List<EmailAddress>>();
   for (RecipientType type : headerToMap.keySet()) {
     ArrayList<EmailAddress> addrs = new ArrayList<EmailAddress>();
     for (InternetAddress iaddr : headerToMap.get(type)) {
       addrs.add(new EmailAddress(iaddr.getAddress(), iaddr.getPersonal()));
     }
     tos.put(type, addrs);
   }
   // add the actual recipients
   LinkedList<EmailAddress> addys = new LinkedList<EmailAddress>();
   for (InternetAddress t : to) {
     addys.add(new EmailAddress(t.getAddress(), t.getPersonal()));
   }
   tos.put(RecipientType.ACTUAL, addys);
   msg.setRecipients(tos);
   // add additional headers
   msg.setHeaders(additionalHeaders);
   // add attachments
   msg.setAttachments(attachments);
   // send message
   emailService.send(msg);
 }
Esempio n. 2
0
 @Test
 public void testInvalidReplyTo() throws Exception {
   EmailMessage msg = new EmailMessage("test", subject, content);
   msg.addReplyTo(new EmailAddress("test", "test"));
   try {
     emailService.send(msg);
     Assert.fail("Should not be able to send successfully with invalid 'reply to'.");
   } catch (AddressValidationException e) {
     // expected
   }
 }