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


   */
  public void sendNotificationMail(String userName) {

    try {
      MimeMessage msg = mailSender.createMimeMessage();
      MimeMessageHelper helper = new MimeMessageHelper(msg, true, DEFAULT_ENCODING);

      helper.setTo("springside3.demo@gmail.com");
      helper.setFrom("springside3.demo@gmail.com");
      helper.setSubject("用户修改通知");

      String content = generateContent(userName);
      helper.setText(content, true);

      File attachment = generateAttachment();
      helper.addAttachment("mailAttachment.txt", attachment);

      mailSender.send(msg);
      logger.info("HTML版邮件已发送至springside3.demo@gmail.com");
    } catch (MessagingException e) {
      logger.error("构造邮件失败", e);
View Full Code Here

        public void run() {
            try {
                mailSender.send(new MimeMessagePreparator() {
                    public void prepare(MimeMessage mimeMessage) throws MessagingException {
                        MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, "UTF-8");
                        message.setFrom(from);
                        message.setTo(to);
                        message.setSubject(subject);
                        message.setText(msg, true);
                    }
                });
            } catch (Exception e) {
                logger.warn("Failed to send " + subject + "email to " + Arrays.asList(to), e);
            }
View Full Code Here

  @Async
  public void sendEmail(final String sendFrom, final String[] sendTo,
      final String subject, final String sendContext) {
    try {
      MimeMessage mm = mailSender.createMimeMessage();
      MimeMessageHelper mmh = new MimeMessageHelper(mm, true, "UTF-8");
      // 寄件人
      mmh.setFrom(sendFrom);
      // 收件人
      mmh.setTo(sendTo);
      // 主旨
      mmh.setSubject(subject);
      // html信件內容
      mmh.setText(sendContext, true);

      mailSender.send(mm);

      logger.debug("send mail from:{} to {} ,{}-{}", new String[] {
          sendFrom, Arrays.toString(sendTo), subject, sendContext });
View Full Code Here

    mailSender.setPort(smtpPort);
    mailSender.setProtocol("smtp");


    MimeMessage message = mailSender.createMimeMessage();
    MimeMessageHelper helper = new MimeMessageHelper(message);
    try {
      helper.setTo(ADMIN_USER + "@localhost");
      helper.setFrom(from);
      helper.setSubject(subject);
      helper.setText(msg);
      mailSender.send(message);
    }
    catch (MessagingException e) {
      throw new RuntimeException(e);
    }
View Full Code Here

     */
    public static void sendMail(String from, String[] tos, String[] ccs, String title, String text,
            List<Pair<String, InputStreamSource>> attachments, String priority, boolean isHtml,
            String encoding) throws MailException, MessagingException {
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, encoding);

        messageHelper.setFrom(from);
        messageHelper.setBcc(from);

        if (ArrayUtils.isEmpty(tos)) {
            throw new IllegalArgumentException("<tos> can not be null or empty!");
        } else {
            messageHelper.setTo(tos);
        }

        if (!ArrayUtils.isEmpty(ccs)) {
            messageHelper.setCc(ccs);
        }

        messageHelper.setSubject(title);
        messageHelper.setText(text, isHtml);

        if (attachments != null) {
            for (Pair<String, InputStreamSource> pair : attachments) {
                messageHelper.addAttachment(pair.a, pair.b);
            }
        }

        mimeMessage = messageHelper.getMimeMessage();
        if (priority != null) {
            mimeMessage.addHeader("X-Priority", priority);
        }

        mailSender.send(mimeMessage);
View Full Code Here

      Assert.isTrue( to != null && to.length() != 0 && to.indexOf( '@' ) > -1 );
      logger.debug("Sending email to: {} from: {} subject: {}", new Object[]{to, from, subject});
      javaMailSender.send(new MimeMessagePreparator() {
        @Override
        public void prepare( MimeMessage mimeMessage ) throws MessagingException {
          MimeMessageHelper message;
          message = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED, MAIL_ENCODING);
          message.setFrom( from );
          message.setTo( InternetAddress.parse( to ) );
          message.setSubject( subject );
          message.setText( body, false );

          for (File attachment : attachments)
            message.addAttachment( attachment.getName(), attachment );

          logger.debug("Sending email: {}", subject);
        }
      } );
    }
View Full Code Here

   */
  public void sendNotificationMail(String userName) {

    try {
      MimeMessage msg = mailSender.createMimeMessage();
      MimeMessageHelper helper = new MimeMessageHelper(msg, true, DEFAULT_ENCODING);

      helper.setTo("springside3.demo@gmail.com");
      helper.setFrom("springside3.demo@gmail.com");
      helper.setSubject("用户修改通知");

      String content = generateContent(userName);
      helper.setText(content, true);

      File attachment = generateAttachment();
      helper.addAttachment("mailAttachment.txt", attachment);

      mailSender.send(msg);
      logger.info("HTML版邮件已发送至springside3.demo@gmail.com");
    } catch (MessagingException e) {
      logger.error("构造邮件失败", e);
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

    }

    protected MimeMessage prepareMessage(MailConfig mailConfig, Map<String, Object> context) throws Exception {
        //
        MimeMessage mimeMessage = mailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage);
        // from
        if(StringUtils.hasText(mailConfig.getFrom())) {
            String from = evaluate(mailConfig.getFrom(), context);
            if(from.contains("|")) {
                String[] parts = StringUtils.split(from, "|");
                mimeMessageHelper.setFrom(parts[0], parts[1]);
            } else {
                mimeMessageHelper.setFrom(from);
            }
        }
        // to
        for(String to : mailConfig.getTo()) {
            to = evaluate(to, context);
            if(to.contains("|")) {
                String[] parts = StringUtils.split(to, "|");
                mimeMessageHelper.addTo(parts[0], parts[1]);
            } else {
                mimeMessageHelper.addTo(to);
            }
        }
        // cc
        for(String cc : mailConfig.getCc()) {
            cc = evaluate(cc, context);
            if(cc.contains("|")) {
                String[] parts = StringUtils.split(cc, "|");
                mimeMessageHelper.addTo(parts[0], parts[1]);
            } else {
                mimeMessageHelper.addTo(cc);
            }
        }
        // subject
        String subject = evaluate(mailConfig.getSubject(), context);
        mimeMessageHelper.setSubject(subject);
        // content
        String content = evaluate(mailConfig.getContent(), context);
        mimeMessageHelper.setText(content, true);
        //
        return mimeMessage;
    }
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.