Package org.apache.commons.mail

Examples of org.apache.commons.mail.SimpleEmail


    @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

    return "An error occurred and we trapped him: \n\n" + "URL: " + referer + "\n" + params + "User-id : "
        + (currentUser != null ? currentUser : "UNLOGGED") + "\nException: \n" + stackTrace;
  }
 
  public SimpleEmail toSimpleMail() throws EmailException {
    SimpleEmail email = new SimpleEmail();
    email.addTo(to);
    email.setSubject(subject);
    email.setMsg(getMsg());
    email.setFrom(from, fromName);
    return email;
  }
View Full Code Here

  }

  public void register(ErrorMail errorMail) {
    logger.error(errorMail.getMsg());
    try {
      SimpleEmail email = errorMail.toSimpleMail();
      mailer.send(email);
    } catch (Exception ex) {
      logger.error("Unable to send error by email. THIS IS HARDCORE, nobody will know about this error.", ex);
    }
  }
View Full Code Here

    return this;
  }

  @Override
  public Email to(String name, String toMail) {
    SimpleEmail email = new SimpleEmail();
    try {
      email.addTo(toMail, name);
    } catch (EmailException e) {
      throw new IllegalArgumentException(e);
    }
    return email;
  }
View Full Code Here

    return this;
  }

  @Override
  public Email to(String name, String toMail) {
    SimpleEmail email = new SimpleEmail();
    try {
      email.addTo(toMail, name);
    } catch (EmailException e) {
      throw new IllegalArgumentException(e);
    }
    return email;
  }
View Full Code Here

    return "An error occurred and we trapped him: \n\n" + "URL: " + referer + "\n" + params + "Headers:\n" + headers + "User-id : "
        + (currentUser != null ? currentUser : "UNLOGGED") + "\nException: \n" + stackTrace;
  }
 
  public SimpleEmail toSimpleMail() throws EmailException {
    SimpleEmail email = new SimpleEmail();
    email.addTo(to);
    email.setSubject(subject);
    email.setMsg(getMsg());
    email.setFrom(from, fromName);
    return email;
  }
View Full Code Here

      throw new ProcessEngineException("Could not create HTML email", e);
    }
  }

  protected SimpleEmail createTextOnlyEmail(String text) {
    SimpleEmail email = new SimpleEmail();
    try {
      email.setMsg(text);
      return email;
    } catch (EmailException e) {
      throw new ProcessEngineException("Could not create text-only email", e);
    }
  }
View Full Code Here

    return this;
  }

  @Override
  public Email to(String name, String toMail) {
    SimpleEmail email = new SimpleEmail();
    try {
      email.addTo(toMail, name);
    } catch (EmailException e) {
      throw new IllegalArgumentException(e);
    }
    return email;
  }
View Full Code Here

TOP

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

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.