Package org.springframework.mail.javamail

Examples of org.springframework.mail.javamail.MimeMessageHelper


        }
        Session mailSession = this.createSmtpSession(emailSetting);
        if (mailSession != null) {
            Transport transport = mailSession.getTransport();
            MimeMessage msg = new MimeMessage(mailSession);
            MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8");
            helper.setFrom(emailSetting.getFrom_address());
            helper.setTo(toAddress);
            helper.setSubject(subject);
            helper.setText(text, true);
            transport.connect();
            transport.sendMessage(msg,
                    msg.getRecipients(Message.RecipientType.TO));
        }
    }
View Full Code Here


        Session mailSession = createSmtpSession(emailSetting);

        if (mailSession != null) {
            Transport transport = mailSession.getTransport();
            MimeMessage msg = new MimeMessage(mailSession);
            MimeMessageHelper helper = new MimeMessageHelper(msg, true, "utf-8");
            helper.setFrom(from);
            helper.setTo(to);
            helper.setSubject(subject);
            helper.setText(text, true);
            if (fileNames != null && files != null) {
                String fileName = null;
                File file = null;
                for (int i = 0; i < fileNames.length; i++) {
                    fileName = fileNames[i];
                    file = files[i];
                    if (fileName != null && file != null) {
                        helper.addAttachment(fileName, file);
                    }
                }
            }
            transport.connect();
            transport.sendMessage(msg,
View Full Code Here

    public MimeMessagePreparator prepareMail(final String to, final String from, final String subject,
                                             final String template, final Map model) {
        return new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setTo(to);
                message.setFrom(from);
                message.setSubject(subject);
                String text = VelocityEngineUtils.mergeTemplateIntoString(
                        velocityEngine, template, model);
                message.setText(text, true);
            }
        };
    }
View Full Code Here

      this.fromPersonal = fromPersonal;
    }

    public void prepare(MimeMessage mimeMessage) throws Exception {
      simpleMailMessage.copyTo(new MimeMailMessage(mimeMessage));
      MimeMessageHelper helper = new MimeMessageHelper(mimeMessage,mimeMessage.getEncoding());
      helper.setText(simpleMailMessage.getText(),true);
     
      if(StringUtils.isNotEmpty(fromPersonal)) {
        mimeMessage.setFrom(new InternetAddress(simpleMailMessage.getFrom(),fromPersonal));
      }
    }
View Full Code Here

    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(emailAddresses);
        helper.setText(bodyText);
        helper.setSubject(subject);

        helper.addAttachment(attachmentName, resource);

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

        if (senderName == null || senderName.equals("")) {
            throw new MailServiceException("No se ha especificado nombre de remitente");
        }

        MimeMessage message = this.sender.createMimeMessage();
        MimeMessageHelper helper;

        try {
            //INDICAMOS QUE EL MENSAJE ES UN MENSAJE MULTI-PARTE
            helper = new MimeMessageHelper(message, true);
        } catch (MessagingException e2) {
            throw new MailServiceException(e2);
        }

        try {
            helper.setTo(messageToAddresses);
            helper.setSubject(messageSubject);
            helper.setText(messageBody, true);//INDICAMOS QUE EL CUERPO DEL MENSAJE VA EN HTML
            helper.setSentDate(new Date());
            helper.setFrom(sender);
            helper.setReplyTo(sender);
            if (attachMents != null && attachMents.size() > 0) {
                for (File item : attachMents) {
                    helper.addAttachment(item.getName(), item);
                }
            }
        } catch (Exception ex) {
            throw new MailServiceException("Ha habido problemas con la pasarela de correo: " + ex.toString(), ex);
        }
View Full Code Here

      }
     
      // now build the actual message
      MimeMessage myMimeMessage = aMimeMessage;
      // wrap it in a MimeMessageHelper - since some things are easier with that
      MimeMessageHelper myMimeMessageHelper = new MimeMessageHelper(myMimeMessage);
     
      // set headers
     
      // subject
      myMimeMessageHelper.setSubject
                (
                  TextRenderUtil.getInstance().render
                  (
                    (String)propMap.get(MessageRefProp.JR_SUBJECT.toString()),
                    myRenderContext
                  )
                );

      // TODO: implement DKIM, figure out subetha
     
      String mySenderEmailPattern = aSendConfig.getSenderEmailPattern();
      String mySenderEmail = TextRenderUtil.getInstance().render(mySenderEmailPattern, myRenderContext);
      myMimeMessage.setSender(new InternetAddress(mySenderEmail));
     
      myMimeMessageHelper.setTo(aSubscriber.getEmail());
     
      // from
      myMimeMessageHelper.setFrom
                (
                  TextRenderUtil.getInstance().render
                  (
                    (String)propMap.get(MessageRefProp.JR_FROM_EMAIL.toString()),
                    myRenderContext
                  ),
                  TextRenderUtil.getInstance().render
                  (
                    (String)propMap.get(MessageRefProp.JR_FROM_NAME.toString()),
                    myRenderContext
                  )
                );
   
 
          // see how to set body
     
      // if we have both text and html, then do multipart
      if (myTextBody.trim().length() > 0 && myHtmlBody.trim().length() > 0) {
       
        // create wrapper multipart/alternative part
        MimeMultipart ma = new MimeMultipart("alternative");
        myMimeMessage.setContent(ma);
        // create the plain text
        BodyPart plainText = new MimeBodyPart();
        plainText.setText(myTextBody);
        ma.addBodyPart(plainText);
        // create the html part
        BodyPart html = new MimeBodyPart();
        html.setContent(myHtmlBody, "text/html");
        ma.addBodyPart(html);
      }
     
      // if only HTML, then just use that
      else if (myHtmlBody.trim().length() > 0) {
        myMimeMessageHelper.setText(myHtmlBody, true);
      }
     
      // if only text, then just use that
      else if (myTextBody.trim().length() > 0) {
        myMimeMessageHelper.setText(myTextBody, false);
      }
     
      // if neither text nor HTML, then the message is being skipped,
      // so we just return null
      else {
View Full Code Here

        final NotificationStep notificationStep = ((NotificationAction) getAction()).getNotificationStep();

        try {
            JavaMailSender sender = mailSender();
            MimeMessage mimeMessage = sender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            for (String s : notificationStep.getEmails()) {
                helper.addTo(s);
            }
            helper.setFrom(configuration.getSenderEmail(), configuration.getSenderName());
            helper.setSubject(notificationStep.getSubject());
            helper.setText(((NotificationAction) getAction()).getMessage());
            sender.send(mimeMessage);
            return new NotificationResult(getAction());
        } catch (MailSendException e) {
            log.error(e.getMessage(), e);
            return new NotificationResultFailed(getAction(), (e.getMessageExceptions() != null && e.getMessageExceptions().length > 0) ? e.getMessageExceptions()[0] : e);
View Full Code Here

            throw new IllegalArgumentException("Recipients list should not be empty");
        }
        try {
            JavaMailSender sender = this.mailSender;
            MimeMessage mimeMessage = sender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
            for (String s : recipients) {
                helper.addTo(s);
            }
            helper.setFrom(configuration.getSenderEmail(), configuration.getSenderName());
            helper.setSubject(subject);
            helper.setText(message);
            sender.send(mimeMessage);
        } catch (MessagingException e) {
            throw new RuntimeException("Failed to create message", e);
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("Failed to create message", 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.