예제 #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);
 }
예제 #2
0
 @Test
 public void testNoRecipients() throws Exception {
   EmailMessage msg = new EmailMessage(from.getAddress(), subject, content);
   try {
     emailService.send(msg);
     Assert.fail("Should not be able to send successfully with no recipients.");
   } catch (NoRecipientsException e) {
     // expected
   }
 }
예제 #3
0
 @Test
 public void testInvalidFrom() throws Exception {
   EmailMessage msg = new EmailMessage("test", subject, content);
   try {
     emailService.send(msg);
     Assert.fail("Should not be able to send successfully with invalid 'from'.");
   } catch (AddressValidationException e) {
     // expected
   }
 }
예제 #4
0
 @Test
 public void testSend() throws Exception {
   emailService.send(
       from.getAddress(),
       to[0].getAddress() + ", [email protected]",
       subject,
       content,
       headerTo[0].getAddress(),
       replyTo[0].getAddress(),
       additionalHeaders);
 }