Package org.apache.commons.mail

Examples of org.apache.commons.mail.Email


  public void execute(ActivityExecution execution) {
   
    boolean doIgnoreException = Boolean.parseBoolean(getStringFromField(ignoreException, execution));
    String exceptionVariable = getStringFromField(exceptionVariableName, execution);
    Email email = null;
    try {
      String toStr = getStringFromField(to, execution);
      String fromStr = getStringFromField(from, execution);
      String ccStr = getStringFromField(cc, execution);
      String bccStr = getStringFromField(bcc, execution);
      String subjectStr = getStringFromField(subject, execution);
      String textStr = textVar == null ? getStringFromField(text, execution)
          : getStringFromField(getExpression(execution, textVar), execution);
      String htmlStr = htmlVar == null ? getStringFromField(html, execution)
          : getStringFromField(getExpression(execution, htmlVar), execution);
      String charSetStr = getStringFromField(charset, execution);
 
      email = createEmail(textStr, htmlStr);
 
      addTo(email, toStr);
      setFrom(email, fromStr);
      addCc(email, ccStr);
      addBcc(email, bccStr);
      setSubject(email, subjectStr);
      setMailServerProperties(email);
      setCharset(email, charSetStr);
 
      email.send();
     
    } catch (ActivitiException e) {
      handleException(execution, e.getMessage(), e, doIgnoreException, exceptionVariable);
    } catch (EmailException e) {
      handleException(execution, "Could not send e-mail in execution " + execution.getId(), e, doIgnoreException, exceptionVariable);
View Full Code Here


    @Test(expected = MailException.class)
    public void buildMessageWithoutFrom() throws EmailException {
        new YalpBuilder().build();

        Email email = new SimpleEmail();
        email.addTo("from@yalpframework.com");
        email.setSubject("subject");
        Mail.buildMessage(new SimpleEmail());
    }
View Full Code Here

    @Test(expected = MailException.class)
    public void buildMessageWithoutRecipient() throws EmailException {
        new YalpBuilder().build();

        Email email = new SimpleEmail();
        email.setFrom("from@yalpframework.com");
        email.setSubject("subject");
        Mail.buildMessage(email);
    }
View Full Code Here

    @Test(expected = MailException.class)
    public void buildMessageWithoutSubject() throws EmailException {
        new YalpBuilder().build();

        Email email = new SimpleEmail();
        email.setFrom("from@yalpframework.com");
        email.addTo("to@yalpframework.com");
        Mail.buildMessage(email);
    }
View Full Code Here

    @Test
    public void buildValidMessages() throws EmailException {
        new YalpBuilder().build();

        Email email = new SimpleEmail();
        email.setFrom("from@yalpframework.com");
        email.addTo("to@yalpframework.com");
        email.setSubject("subject");
        Mail.buildMessage(email);

        email = new SimpleEmail();
        email.setFrom("from@yalpframework.com");
        email.addCc("to@yalpframework.com");
        email.setSubject("subject");
        Mail.buildMessage(email);

        email = new SimpleEmail();
        email.setFrom("from@yalpframework.com");
        email.addBcc("to@yalpframework.com");
        email.setSubject("subject");
        Mail.buildMessage(email);
    }
View Full Code Here

    if (LOG.isTraceEnabled()) {
      LOG.trace("sending email to {} with server settings {}",
          smtpMessage.getTo(), settings);
    }

    Email email = new SimpleEmail();
    email.setHostName(settings.getSmtpHost());
    email.setSmtpPort(settings.getSmtpPort());
    email.setFrom(smtpMessage.getFrom().toString());
    email.setSubject(smtpMessage.getSubject());
    email.setMsg(smtpMessage.getContent());
    email.setTo(smtpMessage.getTo());
    email.setSentDate(smtpMessage.getDateSent().toDate());
    if (settings.getAuthentication() != null) {
      email.setAuthentication(settings.getAuthentication().getUserName(),
          settings.getAuthentication().getPassword());
    }
    if (settings.isUseSsl()) {
      // enable the use of SSL for SMTP connections. NOTE: should
      // only be used for cases when the SMTP server port only supports
      // SSL connections (typically over port 465).
      email.setSSLOnConnect(true);
    } else {
      // Support use of the STARTTLS command (see RFC 2487 and RFC 3501)
      // to switch the connection to be secured by TLS for cases where the
      // server supports both SSL and non-SSL connections. This is
      // typically the case for most modern mail servers.
      email.setStartTLSEnabled(true);
    }
    email.setSocketConnectionTimeout(settings.getConnectionTimeout());
    email.setSocketTimeout(settings.getSocketTimeout());
    email.send();

    if (LOG.isTraceEnabled()) {
      LOG.trace("email sent to " + smtpMessage.getTo());
    }
  }
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

    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 ProcessEngineException("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

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.