Пример #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 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
   }
 }
Пример #3
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
   }
 }
Пример #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);
 }
Пример #5
0
  @AfterClass
  public static void tearDownEmailService() throws Exception {
    emailService.destroy();

    if (wiser != null && wiser.getServer().isRunning()) {
      if (LOG_SENT_EMAIL) {
        for (WiserMessage msg : wiser.getMessages()) {
          log.info(msg);
        }
      }
      wiser.stop();
    }
  }
Пример #6
0
  @BeforeClass
  public static void setUpEmailService() throws Exception {
    log.info("Setting up test case...");
    final ServerConfigurationService config = context.mock(ServerConfigurationService.class);

    emailService = new BasicEmailService();
    emailService.setServerConfigurationService(config);

    emailService.setSmtp(HOST);
    emailService.setSmtpPort(Integer.toString(PORT));
    emailService.setMaxRecipients("100");
    emailService.setOneMessagePerConnection(false);
    emailService.setAllowTransport(ALLOW_TRANSPORT);

    context.checking(
        new Expectations() {
          {
            allowing(config).getServerName();
            will(returnValue("localhost"));

            String connTimeoutKey =
                emailService.propName(BasicEmailService.MAIL_CONNECTIONTIMEOUT_T);
            allowing(config).getString(connTimeoutKey, null);
            will(returnValue(null));

            String timeoutKey = emailService.propName(BasicEmailService.MAIL_TIMEOUT_T);
            allowing(config).getString(timeoutKey, null);
            will(returnValue(null));

            allowing(config).getString(BasicEmailService.MAIL_SENDFROMSAKAI, "true");
            will(returnValue("true"));

            allowing(config).getString(BasicEmailService.MAIL_SENDFROMSAKAI_EXCEPTIONS, null);
            will(returnValue(null));

            allowing(config).getString(BasicEmailService.MAIL_SENDFROMSAKAI_FROMTEXT, "{}");
            will(returnValue("{}"));
          }
        });

    System.err.println("Initing EmailService...");
    emailService.init();
    System.err.println("EmailService inited.");

    if (ALLOW_TRANSPORT) {
      System.err.println("Starting internal mail server...");
      wiser = new Wiser();
      wiser.setPort(PORT);
      wiser.start();
      System.err.println("Internal mail server started.");
    }
  }
Пример #7
0
 @Test
 public void testSendMailAll() throws Exception {
   emailService.sendMail(
       from, to, subject, content, headerToMap, replyTo, additionalHeaders, attachments);
 }
Пример #8
0
 @Test
 public void testSendMailBasic() throws Exception {
   emailService.sendMail(from, to, subject, content, null, null, null, null);
 }