Package org.springframework.mail.javamail

Examples of org.springframework.mail.javamail.MimeMessageHelper


  public void sendMessage(String template, Object model,
      MailEngineCallback action) {
    MimeMessage message = ((JavaMailSenderImpl) mailSender)
        .createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message);
    try {
      action.setMail(helper);
    } catch (Exception e) {
      if (logger.isDebugEnabled()) {
        logger.error(e.getMessage());
      }
    }
    if (template != null) {
      try {
        helper.setText(getMailText(template, model), true);
      } catch (Exception e) {
        if (logger.isDebugEnabled()) {
          logger.error(e.getMessage());
        }
      }
View Full Code Here


                            String subject, String attachmentName)
    throws MessagingException {
        MimeMessage message = ((JavaMailSenderImpl) mailSender).createMimeMessage();

        // use the true flag to indicate you need a multipart message
        MimeMessageHelper helper = new MimeMessageHelper(message, true);

        helper.setTo(recipients);

        // use the default sending if no sender specified
        if (sender == null) {
            helper.setFrom(defaultFrom);
        } else {
           helper.setFrom(sender);
        }

        helper.setText(bodyText);
        helper.setSubject(subject);

        helper.addAttachment(attachmentName, resource);

        ((JavaMailSenderImpl) mailSender).send(message);
    }
View Full Code Here

        logger.debug("subject : {}", subject);

        try {
            JavaMailSender javaMailSender = mailServerInfo.getJavaMailSender();
            MimeMessage msg = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(msg, true, "UTF-8");
            helper.setFrom(from);
            helper.setSubject(subject);
            helper.setTo(InternetAddress.parse(to));
            helper.setText(content, true);

            if (cc != null) {
                helper.setCc(InternetAddress.parse(cc));
            }

            if (bcc != null) {
                helper.setBcc(InternetAddress.parse(bcc));
            }

            for (Map.Entry<String, InputStreamSource> entry : mailDto
                    .getAttachments().entrySet()) {
                helper.addAttachment(entry.getKey(), entry.getValue());
            }

            javaMailSender.send(msg);
            logger.debug("send mail from {} to {}", from, to);
            mailDto.setSuccess(true);
View Full Code Here

                isMultipart, isHtml, to, subject, content);

        // Prepare message using a Spring helper
        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        try {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
            message.setTo(to);
            message.setFrom(from);
            message.setSubject(subject);
            message.setText(content, isHtml);
            javaMailSender.send(mimeMessage);
            log.debug("Sent e-mail to User '{}'!", to);
        } catch (Exception e) {
            log.warn("E-mail could not be sent to user '{}', exception is: {}", to, e.getMessage());
        }
View Full Code Here

    JavaMailSender mailSender = MailingContext.getMailSender();
    //creates the mail message preparator from JobDataMap set in MailingServiceImpl
    MimeMessagePreparator preparator = new MimeMessagePreparator() {
          public void prepare(MimeMessage mimeMessage) throws Exception {
           VelocityEngine velocityEngine = MailingContext.getVelocityEngine();
             MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
             MailMessage mailMessage = (MailMessage) dataMap.get("message");
             message.setFrom(mailMessage.getMsgFrom());
             message.setTo(mailMessage.getMsgTo());
             if (!StringUtil.isEmpty(mailMessage.getMsgBcc()))
               message.setBcc(mailMessage.getMsgBcc());
             if (!StringUtil.isEmpty(mailMessage.getMsgCc()))
             message.setCc(mailMessage.getMsgCc());
             message.setSubject(mailMessage.getSubject());
             String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailMessage.getTemplate(), mailMessage.getDataMap());
             message.setText(text, true);
             _log.info("Sending email to ["+mailMessage.getMsgTo()+"] with subject ["+mailMessage.getSubject()+"].");
          }
       };
       //send the mail message...
       mailSender.send(preparator);
View Full Code Here

    sender.setUsername(email.getUsername());
    sender.setPassword(email.getPassword());
    sender.send(new MimeMessagePreparator() {
      public void prepare(MimeMessage mimeMessage)
          throws MessagingException, UnsupportedEncodingException {
        MimeMessageHelper msg = new MimeMessageHelper(mimeMessage,
            false, email.getEncoding());
        msg.setSubject(tpl.getForgotPasswordSubject());
        msg.setTo(to);
        msg.setFrom(email.getUsername(), email.getPersonal());
        String text = tpl.getForgotPasswordText();
        text = StringUtils.replace(text, "${uid}", String.valueOf(uid));
        text = StringUtils.replace(text, "${username}", username);
        text = StringUtils.replace(text, "${resetKey}", resetKey);
        text = StringUtils.replace(text, "${resetPwd}", resetPwd);
        msg.setText(text);
      }
    });
  }
View Full Code Here

    public MimeMessagePreparator buildMimeMessagePreparator(final Map<String,Object> props) {
         MimeMessagePreparator preparator = new MimeMessagePreparator() {
             public void prepare(MimeMessage mimeMessage) throws Exception {
                 EmailTarget emailUser = (EmailTarget) props.get(EmailPropertyType.USER.getType());
                 EmailInfo info = (EmailInfo) props.get(EmailPropertyType.INFO.getType());
                 MimeMessageHelper message = new MimeMessageHelper(mimeMessage, (info.getAttachments() != null && info.getAttachments().size() > 0));
                 message.setTo(emailUser.getEmailAddress());
                 message.setFrom(info.getFromAddress());
                 message.setSubject(info.getSubject());
                 if (emailUser.getBCCAddresses() != null && emailUser.getBCCAddresses().length > 0) {
                     message.setBcc(emailUser.getBCCAddresses());
                 }
                 if (emailUser.getCCAddresses() != null && emailUser.getCCAddresses().length > 0) {
                     message.setCc(emailUser.getCCAddresses());
                 }
                 String messageBody = info.getMessageBody();
                 if (messageBody == null) {                 
                     messageBody = buildMessageBody(info, props);
                 }
                 message.setText(messageBody, true);
                 for (Attachment attachment : info.getAttachments()) {
                     ByteArrayDataSource dataSource = new ByteArrayDataSource(attachment.getData(), attachment.getMimeType());
                     message.addAttachment(attachment.getFilename(), dataSource);
                 }
             }
         };
         return preparator;
               
View Full Code Here

    public void send(String to, String subject, String message) {
        LOG.debug("Sending email to: " + to + " with subject: " + subject);
        try {

            final MimeMessage mimeMessage = javaMailSender.createMimeMessage();
            final MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
            helper.setTo(new InternetAddress(to));
            helper.setSubject(subject);
            helper.setText(message, true);
            helper.setFrom(new InternetAddress(FROM));
            javaMailSender.send(mimeMessage);
        } catch (MessagingException e) {
            throw Throwables.propagate(e);
        }
    }
View Full Code Here

    @Override
    public MimeMessagePreparator messagePreparator(final String emailTo, final String emailFrom, final String subject, final String emailText) {
        return new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setFrom(emailFrom);
                message.setTo(emailTo);
                message.setSubject(subject);
                message.setText(emailText, true);
            }
        };
    }
View Full Code Here

    protected MimeMessagePreparator prepareSuccessMessage(final String userId, final String template, final String status,
            final String server) {
        return new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
                CbUser user = userDetailsService.getDetails(userId, UserFilterField.USERID);
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setFrom(msgFrom);
                message.setTo(user.getUsername());
                message.setSubject("Cloudbreak - stack installation");
                message.setText(getEmailBody(user.getGivenName(), status, server, template), true);
            }
        };
    }
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.