Package org.apache.commons.mail

Examples of org.apache.commons.mail.SimpleEmail


    }
  }

  private SimpleEmail createEmailFor(String msg, Throwable e)
      throws EmailException {
    SimpleEmail email = new SimpleEmail();
    String mailingList = env.get(TARGET_MAILING_LIST);
    email.addTo(mailingList);
    email.setSubject("production error");
    email.setMsg(msg + "\nException: \n" + stackAsString(e));
    String from = env.get("vraptor.simplemail.main.from");
    String fromName = env.get("vraptor.simplemail.main.from.name");
    email.setFrom(from, fromName);
    return email;
  }
View Full Code Here


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

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

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

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

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

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

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

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

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

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

   *
   * @param mailInfo
   *            待发送的邮件的信息
   */
  public static boolean sendTextMail(MailSenderInfo mailInfo) {
    SimpleEmail email = new SimpleEmail();
    try {

      email.setHostName(mailInfo.getHostName()); // 设定smtp服务器
      email.setSSL(mailInfo.getIsSSL()); // 设定是否使用SSL
      email.setSslSmtpPort(mailInfo.getSslSmtpPort()); // 设定SSL端口
      email.setAuthentication(mailInfo.getUserName(), mailInfo
          .getPassword()); // 设定smtp服务器的认证资料信息
      email.setDebug(mailInfo.getIsDebug()); // 是否用debug模式
      email.addTo(mailInfo.getToAddress(), mailInfo.getToName()); // 设定收件人
      email.setFrom(mailInfo.getFromAddress(), mailInfo.getFromName());
      email.setSubject(mailInfo.getSubject());
      email.setCharset(mailInfo.getCharset());// 设定内容的语言集
      email.setMsg(mailInfo.getContent());// 设定邮件内容
      email.send();// 发送邮件
      return true;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return false;
View Full Code Here

   * @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

    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);
        }
View Full Code Here

  } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
  } // end of catch

  SimpleEmail email = new SimpleEmail();
  String login = (String) profileInfo.get("login");
  String to = login;
  String from = (String) context.
      getInitParameter("moderation.mail.from.address");
  String subject = (String) context.
      getInitParameter("moderated.mail.subject");
  String baseurl = (String) context.
      getInitParameter("main.baseurl");
  String fromDisplayName = (String) context.
      getInitParameter("moderation.mail.from.displayName");

  if (to == null || to.trim().length() == 0) {
      // assert !(empty to)
      throw new RuntimeException("Invalid profile info, no 'login': " +
               to);

  } // end of if

  if (from == null || from.trim().length() == 0) {
      // assert !(empty from)
      throw new RuntimeException("No 'from' parameter: " + from);
  } // end of if

  if (subject == null || subject.trim().length() == 0) {
      // assert !(empty subject)
      throw new RuntimeException("No 'subject' parameter: " + subject);
  } // end of if

  if (baseurl == null || baseurl.trim().length() == 0) {
      // assert !(empty baseurl)
      throw new RuntimeException("No 'baseurl' parameter: " + baseurl);
  } // end of if

  if (fromDisplayName == null || fromDisplayName.trim().length() == 0) {
      // assert !(empty fromDisplayName)
      throw new RuntimeException("No 'formDisplayName' parameter: " +
               fromDisplayName);

  } // end of if

  // ---

  try {
      String toPattern = bundle.getString("mail.to.pattern");
      String contentPattern = bundle.getString("mail.content.pattern");

      String toDisplayName = MessageFormat.
    format(toPattern,
           new Object[] {
         (String) profileInfo.get("firstName"),
         (String) profileInfo.get("lastName")
           });

      String content = MessageFormat.
    format(contentPattern,
           new Object[] {
         login,
         baseurl,
         fromDisplayName
           });

      email.setMailSession(session);
      email.addTo(to, toDisplayName);
      email.setFrom(from, fromDisplayName);
      email.setSubject(subject);
      email.setCharset("UTF-8");
      email.setMsg(content);

      email.send();
  } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
  } // end of catch
    } // end of sendModerationConfirmation
View Full Code Here

  } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
  } // end of catch

  SimpleEmail email = new SimpleEmail();
  String login = (String) profileInfo.get("login");
  String to = login;
  String from = (String) context.
      getInitParameter("activation.mail.from.address");
  String subject = (String) context.
      getInitParameter("activation.mail.subject");
  String baseurl = (String) context.
      getInitParameter("main.baseurl");
  String fromDisplayName = (String) context.
      getInitParameter("activation.mail.from.displayName");

  if (to == null || to.trim().length() == 0) {
      // assert !(empty to)
      throw new RuntimeException("Invalid profile info, no 'login': " +
               to);

  } // end of if

  if (from == null || from.trim().length() == 0) {
      // assert !(empty from)
      throw new RuntimeException("No 'from' parameter: " + from);
  } // end of if

  if (subject == null || subject.trim().length() == 0) {
      // assert !(empty subject)
      throw new RuntimeException("No 'subject' parameter: " + subject);
  } // end of if

  if (baseurl == null || baseurl.trim().length() == 0) {
      // assert !(empty baseurl)
      throw new RuntimeException("No 'baseurl' parameter: " + baseurl);
  } // end of if

  if (fromDisplayName == null || fromDisplayName.trim().length() == 0) {
      // assert !(empty fromDisplayName)
      throw new RuntimeException("No 'formDisplayName' parameter: " +
               fromDisplayName);

  } // end of if

  // ---

  try {
      String toPattern = bundle.getString("mail.to.pattern");
      String contentPattern = bundle.getString("mail.content.pattern");

      String toDisplayName = MessageFormat.
    format(toPattern,
           new Object[] {
         (String) profileInfo.get("firstName"),
         (String) profileInfo.get("lastName")
           });

      String content = MessageFormat.
    format(contentPattern,
           new Object[] {
         login,
         baseurl,
         fromDisplayName,
         profileInfo.get("id")
           });

      email.setMailSession(session);
      email.addTo(to, toDisplayName);
      email.setFrom(from, fromDisplayName);
      email.setSubject(subject);
      email.setCharset("UTF-8");
      email.setMsg(content);

      email.send();
  } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e.getMessage());
  } // end of catch
    } // end of sendActivationMessage
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.