Package org.springframework.mail.javamail

Examples of org.springframework.mail.javamail.MimeMessageHelper


      if (null == mailMsg.getSendAt()) {
        mimeMsg.setSentDate(new Date());
      } else {
        mimeMsg.setSentDate(mailMsg.getSendAt());
      }
      MimeMessageHelper messageHelper = null;
      String encoding = StringUtils.substringAfter(mailMsg.getContentType(), "charset=");
      if (StringUtils.isEmpty(encoding)) {
        messageHelper = new MimeMessageHelper(mimeMsg);
      } else {
        messageHelper = new MimeMessageHelper(mimeMsg, encoding);
      }
      messageHelper.setText(buildText(mailMsg), StringUtils.contains(mailMsg.getContentType(), "html"));
      String subject = buildSubject(mailMsg);
      messageHelper.setSubject(subject);
      int recipients = addRecipient(mimeMsg, mailMsg);
      beforeSend(mailMsg, mimeMsg);
      if (recipients > 0) {
        mailSender.send(mimeMsg);
        if (logger.isDebugEnabled()) {
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

        // send mail
        try {
            MimeMessagePreparator preparator = new MimeMessagePreparator() {
                public void prepare(MimeMessage mimeMessage)
                        throws Exception {
                    MimeMessageHelper message = new MimeMessageHelper(
                            mimeMessage);
                    message.setTo(invitation.getEmail());
                    message.setFrom(from);
                    message.setSubject("ToCollege.net Invitation");

                    Map<String, Object> model = new HashMap<String, Object>();
                    model.put("inviter", invitation.getInviter());
                    model.put("randomkey", invitation.getRandomkey());
                    model.put("email", invitation.getEmail());

                    Template textTemplate = configurer.getConfiguration()
                            .getTemplate(invitationTemplate);
                    final StringWriter textWriter = new StringWriter();

                    textTemplate.process(model, textWriter);

                    message.setText(textWriter.toString(), true);

                    log.info("Inviting: " + invitation.getEmail());
                    log.debug("From: " + from);
                    log.debug("Message: " + textWriter.toString());
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

    final ByteArrayResource byteArrayResource = getFileData(pictureName);

    try {

      final MimeMessageHelper helper = new MimeMessageHelper(message, true);

      helper.setFrom("testfrom@springintegration.org");
      helper.setTo("testto@springintegration.org");
      helper.setSubject("Parsing of Attachments");
      helper.setText("Spring Integration Rocks!");

      helper.addAttachment(pictureName, byteArrayResource, "image/png");

    }
    catch (MessagingException e) {
      throw new MailParseException(e);
    }
View Full Code Here

    final MimeMessage rootMessage = mailSender.createMimeMessage();

    try {

      final MimeMessageHelper messageHelper = new MimeMessageHelper(rootMessage, true);

      messageHelper.setFrom("testfrom@springintegration.org");
      messageHelper.setTo("testto@springintegration.org");
      messageHelper.setSubject("Parsing of Attachments");
      messageHelper.setText("Spring Integration Rocks!", "Spring Integration <b>Rocks</b>!");

      final String pictureName = "picture.png";

      final ByteArrayResource byteArrayResource = getFileData(pictureName);

      messageHelper.addInline("picture12345", byteArrayResource, "image/png");

    }
    catch (MessagingException e) {
      throw new MailParseException(e);
    }
View Full Code Here

    private EmailServiceTokenModel sendVerificationEmail(final EmailServiceTokenModel emailVerificationModel, final String emailSubject,
                                                         final String velocityModel, final Map<String, String> resources) {
        MimeMessagePreparator preparator = new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_RELATED, "UTF-8");
                messageHelper.setTo(emailVerificationModel.getEmailAddress());
                messageHelper.setFrom(config.getEmailFromAddress());
                messageHelper.setReplyTo(config.getEmailReplyToAddress());
                messageHelper.setSubject(emailSubject);
                Map model = new HashMap();
                model.put("model", emailVerificationModel);
                String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, velocityModel, model);
                messageHelper.setText(new String(text.getBytes(), "UTF-8"), true);
                      for(String resourceIdentifier: resources.keySet()) {
                   addInlineResource(messageHelper, resources.get(resourceIdentifier), resourceIdentifier);
                }
            }
        };
View Full Code Here

                mimeMessage.setHeader(HEADER_PRIORITY, String.valueOf(email.getPriority().getRank()));
                for (Iterator iter = email.getHeaders().entrySet().iterator(); iter.hasNext();) {
                    Map.Entry entry = (Map.Entry)iter.next();
                    mimeMessage.setHeader(String.valueOf(entry.getKey()), String.valueOf(entry.getValue()));
                }
                MimeMessageHelper message =
                    new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_RELATED, encoding);

                message.setTo(email.getTo());
                message.setBcc(email.getBcc());
                message.setCc(email.getCc());
                message.setFrom(email.getFrom());
                message.setSubject(email.getSubject());
                if (email.getTextBody() != null && email.getHtmlBody() != null) {
                    message.setText(email.getTextBody(), email.getHtmlBody());
                } else {
                    if (email.getTextBody() != null) {
                        message.setText(email.getTextBody(), false);
                    }
                    if (email.getHtmlBody() != null) {
                        message.setText(email.getHtmlBody(), true);
                    }
                }
                if (email.getReplyTo() != null) {
                    message.setReplyTo(email.getReplyTo());
                }
                for (Iterator iter = email.getAttachments().iterator(); iter.hasNext();) {
                    Attachment attachment = (Attachment) iter.next();
                    message.addAttachment(attachment.getName(), attachment.getResource());
                }
                for (Iterator iter = email.getInlineAttachments().iterator(); iter.hasNext();) {
                    Attachment attachment = (Attachment) iter.next();
                    message.addInline(attachment.getName(), attachment.getResource());
                }
            }
        };
    }
View Full Code Here

     */
    protected MimeMessagePreparator generateMimeMessagePreparator(final Email email) {
        return new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
                mimeMessage.setHeader(HEADER_PRIORITY, String.valueOf(email.getPriority().getRank()));
                MimeMessageHelper message =
                    new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_RELATED, getEncoding());
                message.setTo(email.getTo());
                message.setBcc(email.getBcc());
                message.setCc(email.getCc());
                message.setFrom(email.getFrom());
                message.setSubject(email.getSubject());
                if (email.getTextBody() != null) {
                    message.setText(email.getTextBody(), false);
                }
                if (email.getHtmlBody() != null) {
                    message.setText(email.getHtmlBody(), true);
                }
                message.setReplyTo(email.getReplyTo());
                for (Iterator iter = email.getAttachments().iterator(); iter.hasNext();) {
                    Attachment attachment = (Attachment) iter.next();
                    message.addAttachment(attachment.getName(), attachment.getResource());
                }
                for (Iterator iter = email.getInlineAttachments().iterator(); iter.hasNext();) {
                    Attachment attachment = (Attachment) iter.next();
                    message.addInline(attachment.getName(), attachment.getResource());
                }
            }
        };
    }
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

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.