Package org.apache.commons.mail

Examples of org.apache.commons.mail.SimpleEmail


  } 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("lost-password.mail.from.address");
  String subject = (String) context.
      getInitParameter("lost-password.mail.subject");
  String baseurl = (String) context.
      getInitParameter("main.baseurl");
  String fromDisplayName = (String) context.
      getInitParameter("lost-password.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,
         newPassword
           });

      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 sendLostPasswordMessage
View Full Code Here


      String displayName;
      while (iter.hasNext()) {
    addr = (String) iter.next();
    displayName = (String) recipients.get(addr);

    SimpleEmail email = new SimpleEmail();

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

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

      // DEBUG
      System.out.println("#addr=" + addr);
      System.out.println("#displayName=" + displayName);

      try {
    SimpleEmail email = new SimpleEmail();

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

    email.send();
      } catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e.getMessage());
      } // end of catch
  } // end of while
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");
  Date lastModified = (Date) profileInfo.get("lastModified");
  String to = login;
  String from = (String) context.
      getInitParameter("obsolescence.mail.from.address");
  String subject = (String) context.
      getInitParameter("obsolescence.mail.subject");
  String baseurl = (String) context.
      getInitParameter("main.baseurl");
  String fromDisplayName = (String) context.
      getInitParameter("obsolescence.mail.from.displayName");

  if (lastModified != null) {
      // assert lastModified != null
      throw new RuntimeException("Invalid profile info, " +
               "no 'lastModified': " +
               lastModified);

  } // end of if

  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"),
         SimpleDateFormat.
         getDateInstance(SimpleDateFormat.LONG).
         format(lastModified)
           });

      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 sendObsolescenceMessage
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

     * @return the result
     * @throws EmailException the email exception
     * @see {@link SiteApp#writeMail(String, boolean)}
     */
    public static Result sendMail() throws EmailException{
        SimpleEmail email = new SimpleEmail();

        Map<String, String[]> formData = request().body().asFormUrlEncoded();
        email.setFrom(utils.HttpUtil.getFirstValueFromQuery(formData, "from"));
        email.setSubject(utils.HttpUtil.getFirstValueFromQuery(formData, "subject"));
        email.addTo(utils.HttpUtil.getFirstValueFromQuery(formData, "to"));
        email.setMsg(utils.HttpUtil.getFirstValueFromQuery(formData, "body"));
        email.setCharset("utf-8");

        String errorMessage = null;
        boolean sended;
        String result = Mailer.send(email);
        Logger.info(">>>" + result);
View Full Code Here

        Configuration config = play.Play.application().configuration();
        String sender = config.getString("smtp.user") + "@" + config.getString("smtp.domain");
        String resetPasswordUrl = getResetPasswordUrl(hashString);

        try {
            SimpleEmail email = new SimpleEmail();
            email.setFrom(sender)
                 .setSubject("[" + utils.Config.getSiteName() + "] " + Messages.get("site.resetPasswordEmail.title"))
                 .addTo(user.email)
                 .setMsg(Messages.get("site.resetPasswordEmail.mailContents") + "\n\n" + resetPasswordUrl)
                 .setCharset("utf-8");
View Full Code Here


    @Test
    public void testSendSimpleMail() throws Exception {
        //Given
        SimpleEmail email = new SimpleEmail();
        email.setFrom(SENDER_LOCALHOST);
        email.setSubject(SUBJECT);
        email.addTo(RECIPIENT_LOCALHOST);
        email.setMsg(DEFAULT_TEXT_MESSAGE);
        email.setCharset("utf-8");

        //When
        Mailer.send(email);

        //Then
View Full Code Here

      logger.error(noMailingListMessage());
      return;
    }
   
    try {
      SimpleEmail email = createEmailFor(msg, e);
      mailer.asyncSend(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

    }
  }

  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

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.