Package org.apache.commons.mail

Examples of org.apache.commons.mail.Email


   * @param to
   * @param message
   * @throws Exception
   */
  private static void sendEmail(String mailserver, int port, String from, String to, String message, String username, String password) throws EmailException
    Email email = new SimpleEmail();
    email.setDebug(false); // true if you want to debug
        email.setHostName(mailserver);
        if (username != null) {
      email.setAuthentication(username, password);
          email.getMailSession().getProperties().put(
             "mail.smtp.starttls.enable", "true");
    }
        email.setFrom(from, "Wookie Server");
        email.setSubject("Wookie API Key");
        email.setMsg(message);
        email.addTo(to);
        email.send();
  }
View Full Code Here


    @Inject
    private VelocityEngine engine;

    private Email createEmail(boolean html) {
        Email e = null;
        if (html) {
            e = new HtmlEmail();
        } else {
            e = new SimpleEmail();
        }
        e.setHostName(smtpHost);
        if (!StringUtils.isEmpty(smtpUser)) {
            e.setAuthentication(smtpUser, smtpPassword);
        }

        if (!StringUtils.isEmpty(smtpBounceEmail)) {
            e.setBounceAddress(smtpBounceEmail);
        }

        e.setTLS(true);
        e.setSmtpPort(587); //tls port
        e.setCharset("UTF8");
        //e.setDebug(true);

        return e;
    }
View Full Code Here

        if (details.getSubject() == null || !BooleanUtils.xor(ArrayUtils.toArray(details.getMessage() != null, details.getMessageTemplate() != null))) {
            throw new IllegalStateException("Either subject or subjectKey / either template/message/messageKey should be specified");
        }
        Validate.notBlank(details.getFrom());

        Email email = createEmail(details.isHtml());
        String subject = constructSubject(details);
        email.setSubject(subject);

        String emailMessage = constructEmailMessages(details);

        try {
            if (details.isHtml()) {
                ((HtmlEmail) email).setHtmlMsg(emailMessage);
            } else {
                email.setMsg(emailMessage);
            }

            for (String to : details.getTo()) {
                email.addTo(to);
            }
            email.setFrom(details.getFrom());

            email.send();
        } catch (EmailException ex) {
            logger.error("Exception occurred when sending email to " + details.getTo(), ex);
        }
    }
View Full Code Here

  @Override
  public Map<Email, Future<Void>> deliverPostponedMails() {
    Map<Email, Future<Void>> deliveries = new HashMap<Email, Future<Void>>();
    LOGGER.debug("Delivering all {} postponed emails", this.mailQueue.size());
    while (!this.mailQueue.isEmpty()) {
      Email nextMail = this.mailQueue.poll();
      Future<Void> sendingResult = this.asyncSend(nextMail);
      deliveries.put(nextMail, sendingResult);
    }
    return deliveries;
  }
View Full Code Here

    String subjectStr = getStringFromField(subject, execution);
    String textStr = getStringFromField(text, execution);
    String htmlStr = getStringFromField(html, execution);
    String charSetStr = getStringFromField(charset, execution);

    Email email = createEmail(textStr, htmlStr);

    addTo(email, toStr);
    setFrom(email, fromStr);
    addCc(email, ccStr);
    addBcc(email, bccStr);
    setSubject(email, subjectStr);
    setMailServerProperties(email);
    setCharset(email, charSetStr);

    try {
      email.send();
    } catch (EmailException e) {
      throw new ActivitiException("Could not send e-mail", e);
    }
    leave(execution);
  }
View Full Code Here

  @Override
  public Map<Email, Future<Void>> deliverPostponedMails() {
    Map<Email, Future<Void>> deliveries = new HashMap<Email, Future<Void>>();
    LOGGER.debug("Delivering all {} postponed emails", this.mailQueue.size());
    while (!this.mailQueue.isEmpty()) {
      Email nextMail = this.mailQueue.poll();
      Future<Void> sendingResult = this.asyncSend(nextMail);
      deliveries.put(nextMail, sendingResult);
    }
    return deliveries;
  }
View Full Code Here

  @Override
  public Map<Email, Future<Void>> deliverPostponedMails() {
    Map<Email, Future<Void>> deliveries = new HashMap<Email, Future<Void>>();
    LOGGER.debug("Delivering all {} postponed emails", this.mailQueue.size());
    while (!this.mailQueue.isEmpty()) {
      Email nextMail = this.mailQueue.poll();
      Future<Void> sendingResult = this.asyncSend(nextMail);
      deliveries.put(nextMail, sendingResult);
    }
    return deliveries;
  }
View Full Code Here

    spyingMailSystem = new SpyingMailSystem();
  }

  @Test(expected = MailException.class)
  public void buildMessageWithoutFrom() throws EmailException {
    Email emailWithoutFrom = new SimpleEmail();
    emailWithoutFrom.addTo("from@playframework.com");
    emailWithoutFrom.setSubject("subject");
    Mail.buildMessage(new SimpleEmail());
  }
View Full Code Here

    Mail.buildMessage(new SimpleEmail());
  }

  @Test(expected = MailException.class)
  public void buildMessageWithoutRecipient() throws EmailException {
    Email emailWithoutRecipients =
      new SimpleEmail()
        .setFrom("from@playframework.com")
        .setSubject("subject");
    Mail.buildMessage(emailWithoutRecipients);
  }
View Full Code Here

    Mail.buildMessage(emailWithoutRecipients);
  }

  @Test(expected = MailException.class)
  public void buildMessageWithoutSubject() throws EmailException {
    Email emailWithoutSubject = new SimpleEmail();
    emailWithoutSubject.setFrom("from@playframework.com");
    emailWithoutSubject.addTo("to@playframework.com");
    Mail.buildMessage(emailWithoutSubject);
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.mail.Email

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.