Package org.apache.commons.mail

Examples of org.apache.commons.mail.SimpleEmail


  @Before
  public void initializeFixture() throws Exception {
    new PlayBuilder().build();

    simpleEmail =
      new SimpleEmail()
        .setFrom("from@playframework.com")
        .addTo("to@playframework.com")
        .setSubject("subject");

    spyingMailSystem = new SpyingMailSystem();
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

  }

  @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

      emailWitoutRecipients().addBcc("bcc@playframework.com"));
  }

  protected Email emailWitoutRecipients() throws EmailException {
    return
      new SimpleEmail()
        .setFrom("from@playframework.com")
        .setSubject("subject");
  }
View Full Code Here

      throw new ActivitiException("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 ActivitiException("Could not create text-only email", e);
    }
  }
View Full Code Here

  public static void sendSimpleMail(final String from, final String fromName, final String to, final String toName, final String cc, final String bcc, final String bounce, final String subject,
            final String textContent)
    throws EmailException {

    SimpleEmail mail = new SimpleEmail();

    setup(mail, to, toName, from, fromName, cc, bcc, bounce, subject);
    mail.setMsg(textContent);
    mail.send();

  }
View Full Code Here

        host = new URL(configuration.getServerBaseURL()).getHost();
      } catch (MalformedURLException e) {
        // ignore
      }

      SimpleEmail email = new SimpleEmail();
      if (StringUtils.isNotBlank(host)) {
        /*
         * Set headers for proper threading: GMail will not group messages, even if they have same subject, but don't have "In-Reply-To" and
         * "References" headers. TODO investigate threading in other clients like KMail, Thunderbird, Outlook
         */
        if (StringUtils.isNotEmpty(emailMessage.getMessageId())) {
          String messageId = "<" + emailMessage.getMessageId() + "@" + host + ">";
          email.addHeader(IN_REPLY_TO_HEADER, messageId);
          email.addHeader(REFERENCES_HEADER, messageId);
        }
        // Set headers for proper filtering
        email.addHeader(LIST_ID_HEADER, "SonarQube <sonar." + host + ">");
        email.addHeader(LIST_ARCHIVE_HEADER, configuration.getServerBaseURL());
      }
      // Set general information
      email.setCharset("UTF-8");
      String from = StringUtils.isBlank(emailMessage.getFrom()) ? FROM_NAME_DEFAULT : emailMessage.getFrom() + " (SonarQube)";
      email.setFrom(configuration.getFrom(), from);
      email.addTo(emailMessage.getTo(), " ");
      String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "")
        + StringUtils.defaultString(emailMessage.getSubject(), SUBJECT_DEFAULT);
      email.setSubject(subject);
      email.setMsg(emailMessage.getMessage());
      // Send
      email.setHostName(configuration.getSmtpHost());
      configureSecureConnection(email);
      if (StringUtils.isNotBlank(configuration.getSmtpUsername()) || StringUtils.isNotBlank(configuration.getSmtpPassword())) {
        email.setAuthentication(configuration.getSmtpUsername(), configuration.getSmtpPassword());
      }
      email.setSocketConnectionTimeout(SOCKET_TIMEOUT);
      email.setSocketTimeout(SOCKET_TIMEOUT);
      email.send();

    } finally {
      Thread.currentThread().setContextClassLoader(classloader);
    }
  }
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

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.