Package org.springframework.mail.javamail

Examples of org.springframework.mail.javamail.MimeMessageHelper


                    if (StringUtils.isNotBlank(smtpPassword)) {
                        sender.setPassword(smtpPassword);
                    }
                   
                    MimeMessage message = sender.createMimeMessage();
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
                    helper.setTo(to);
                    helper.setFrom(task.getSender());
                    helper.setSubject(task.getSubject());
                    helper.setText(task.getTextBody(), task.getHtmlBody());
                   
                    sender.send(message);
                   
                    execution.setStatus(Status.SENT.name());
                   
View Full Code Here


                    if (StringUtils.isNotBlank(smtpPassword)) {
                        sender.setPassword(smtpPassword);
                    }

                    MimeMessage message = sender.createMimeMessage();
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
                    helper.setTo(to);
                    helper.setFrom(task.getSender());
                    helper.setSubject(task.getSubject());
                    helper.setText(task.getTextBody(), task.getHtmlBody());

                    sender.send(message);

                    execution.setStatus(Status.SENT.name());
View Full Code Here

                    if (StringUtils.isNotBlank(smtpPassword)) {
                        sender.setPassword(smtpPassword);
                    }

                    MimeMessage message = sender.createMimeMessage();
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
                    helper.setTo(to);
                    helper.setFrom(task.getSender());
                    helper.setSubject(task.getSubject());
                    helper.setText(task.getTextBody(), task.getHtmlBody());

                    sender.send(message);

                    execution.setStatus(Status.SENT.name());
View Full Code Here

    public void send(final SimpleMailMessage msg,
                     final Map<String, Object> hTemplateVariables) {
        MimeMessagePreparator preparator = new MimeMessagePreparator() {
            @Override
            public void prepare(MimeMessage mimeMessage) throws Exception {
               MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
               message.setTo(msg.getTo());
               message.setFrom(msg.getFrom());
               message.setSubject(msg.getSubject());

               String body = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/emailBody.vm", hTemplateVariables);

               logger.info("body={}", body);

               message.setText(body, true);
            }
         };

         mailSender.send(preparator);
View Full Code Here

                    if (StringUtils.isNotBlank(smtpPassword)) {
                        sender.setPassword(smtpPassword);
                    }

                    MimeMessage message = sender.createMimeMessage();
                    MimeMessageHelper helper = new MimeMessageHelper(message, true);
                    helper.setTo(to);
                    helper.setFrom(task.getSender());
                    helper.setSubject(task.getSubject());
                    helper.setText(task.getTextBody(), task.getHtmlBody());

                    sender.send(message);

                    execution.setStatus(Status.SENT.name());
View Full Code Here

    }

    MimeMessage mimeMsg = javaMailSender.createMimeMessage();
    try {
      mimeMsg.setSentDate(new Date());
      MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMsg);
      messageHelper.setText(buildText(mailConext), Message.HTML.equals(mailConext
          .getContentType()));
      String subject = buildSubject(mailConext);
      messageHelper.setSubject(subject);
      messageHelper.setFrom(fromMailbox, fromName);
      addRecipient(mimeMsg, javax.mail.Message.RecipientType.TO, mailConext.getTo());
      addRecipient(mimeMsg, javax.mail.Message.RecipientType.CC, mailConext.getCc());
      addRecipient(mimeMsg, javax.mail.Message.RecipientType.BCC, mailConext.getBcc());
      beforeSend(mailConext, mimeMsg);
      if (mimeMsg.getAllRecipients() != null
View Full Code Here

    }
   
    JavaMailSender emailSender = createJavaMailSender(email.getStoreId());
   
    MimeMessage mimeMessage = emailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
    try{
      helper.setFrom(from);
      helper.setTo(to);
      helper.setSubject(subject);
      if(bodyHtml!=null){
        helper.setText(bodyHtml, true);
      }
      if(bodyText!=null){
        helper.setText(bodyText, false);
      }
     
      emailSender.send(mimeMessage);
     
    }catch(MessagingException e){
View Full Code Here

  private static MimeMessage createMimeMessage(String[] toAddrs, String[] ccAddrs,
      String[] bccAddrs, String replyToAddr, String title, String content)
      throws MessagingException {
    MimeMessage msg = SENDER.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(msg, true);
    helper.setFrom(FROM_ADDRESS);
    if (toAddrs != null) {
      helper.setTo(toAddrs);
    }
    if (ccAddrs != null) {
      helper.setCc(ccAddrs);
    }
    if (bccAddrs != null) {
      helper.setBcc(bccAddrs);
    }
    if (replyToAddr != null) {
      helper.setReplyTo(replyToAddr);
    }
    if (!StringUtils.hasLength(title)) {
      title = "无主题";
    }
    if (!StringUtils.hasLength(content)) {
      content = "信息已丢失。";
    }
    msg.setSentDate(new Date());
    helper.setSubject(title);
    helper.setText(content, true);
    return msg;
  }
View Full Code Here

    if (logger.isDebugEnabled()) {
      logger.debug("html content: " + sb);
    }
    // prepare message
    MimeMessage message = sender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8");

    // Remember the TO person email to prevent duplicate mails
    String toPersonEmail;
    try {
      helper.setText(addHeaderAndFooter(sb), true);
      helper.setSubject(getSubject(item));
      helper.setSentDate(new Date());
      helper.setFrom(from);
      // set TO
      if (item.getAssignedTo() != null) {
        helper.setTo(item.getAssignedTo().getEmail());
        toPersonEmail = item.getAssignedTo().getEmail();
      } else {
        helper.setTo(item.getLoggedBy().getEmail());
        toPersonEmail = item.getLoggedBy().getEmail();
      }
      // set CC
      List<String> cclist = new ArrayList<String>();
      if (item.getItemUsers() != null) {
        for (ItemUser itemUser : item.getItemUsers()) {
          // Send only, if person is not the TO assignee
          if (!toPersonEmail.equals(itemUser.getUser().getEmail())) {
            cclist.add(itemUser.getUser().getEmail());
          }
        }

        // sounds complicated but we have to ensure that no null
        // item will be set in setCC(). So we collect the cc items
        // in the cclist and transform it to an stringarray.
        if (cclist.size() > 0) {
          String[] cc = cclist.toArray(new String[0]);
          helper.setCc(cc);
        }
      }
      // send message
      // workaround: Some PSEUDO user has no email address. Because email
      // address
View Full Code Here

      locale = defaultLocale;
    } else {
      locale = StringUtils.parseLocaleString(localeString);
    }
    MimeMessage message = sender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message, "UTF-8");
    try {
      helper.setTo(user.getEmail());
      helper.setSubject(prefix + " " + fmt("loginMailSubject", locale));
      StringBuffer sb = new StringBuffer();
      sb.append("<p>" + fmt("loginMailGreeting", locale) + " "
          + user.getName() + ",</p>");
      sb.append("<p>" + fmt("loginMailLine1", locale) + "</p>");
      sb.append("<table class='jtrac'>");
      sb.append("<tr><th style='background: #CCCCCC'>"
          + fmt("loginName", locale)
          + "</th><td style='border: 1px solid black'>"
          + user.getLoginName() + "</td></tr>");
      sb.append("<tr><th style='background: #CCCCCC'>"
          + fmt("password", locale)
          + "</th><td style='border: 1px solid black'>" + clearText
          + "</td></tr>");
      sb.append("</table>");
      sb.append("<p>" + fmt("loginMailLine2", locale) + "</p>");
      sb.append("<p><a href='" + url + "'>" + url + "</a></p>");
      helper.setText(addHeaderAndFooter(sb), true);
      helper.setSentDate(new Date());
      // helper.setCc(from);
      helper.setFrom(from);
      sendInNewThread(message);
    } catch (Exception e) {
      logger.error("failed to prepare e-mail", e);
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.mail.javamail.MimeMessageHelper

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.