当前位置: 首页>>代码示例>>Java>>正文


Java MimeMessageHelper.setSentDate方法代码示例

本文整理汇总了Java中org.springframework.mail.javamail.MimeMessageHelper.setSentDate方法的典型用法代码示例。如果您正苦于以下问题:Java MimeMessageHelper.setSentDate方法的具体用法?Java MimeMessageHelper.setSentDate怎么用?Java MimeMessageHelper.setSentDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.mail.javamail.MimeMessageHelper的用法示例。


在下文中一共展示了MimeMessageHelper.setSentDate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendHtmlMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * 发送html邮件
 */
@Async("mailAsync")
public void sendHtmlMail(String to, String subject, String content) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		//true表示需要创建一个multipart message
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		mailSender.send(message);
		logger.info("html邮件发送成功");
	} catch (MessagingException e) {
		logger.error("发送html邮件时发生异常!", e);
	}
}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:21,代码来源:MailUtil.java

示例2: sendAttachmentsMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * 发送带附件的邮件
 */
@Async("mailAsync")
public void sendAttachmentsMail(String to, String subject, String content, String filePath) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		FileSystemResource file = new FileSystemResource(new File(filePath));
		String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
		helper.addAttachment(fileName, file);
		mailSender.send(message);
		logger.info("带附件的邮件已经发送。");
	} catch (MessagingException e) {
		logger.error("发送带附件的邮件时发生异常!", e);
	}
}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:23,代码来源:MailUtil.java

示例3: sendInlineResourceMail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/**
 * 发送正文中有静态资源(图片)的邮件
 */
@Async("mailAsync")
public void sendInlineResourceMail(String to, String subject, String content, String rscPath,
		String rscId) {
	MimeMessage message = mailSender.createMimeMessage();
	try {
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
		helper.setFrom(from);
		helper.setTo(to);
		helper.setSubject(subject);
		helper.setText(content, true);
		helper.setSentDate(new Date());
		FileSystemResource res = new FileSystemResource(new File(rscPath));
		helper.addInline(rscId, res);

		mailSender.send(message);
		logger.info("嵌入静态资源的邮件已经发送。");
	} catch (MessagingException e) {
		logger.error("发送嵌入静态资源的邮件时发生异常!", e);
	}
}
 
开发者ID:CharleyXu,项目名称:tulingchat,代码行数:24,代码来源:MailUtil.java

示例4: sendContactNotification

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void sendContactNotification(final ContactForm contactForm) {
      MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @SuppressWarnings({ "rawtypes", "unchecked" })
		public void prepare(MimeMessage mimeMessage) throws Exception {
             MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
             message.setTo(configService.getValue("EMAIL_TO_CONTACT_MESSAGE"));
             message.setBcc("[email protected]");
             message.setFrom(new InternetAddress(contactForm.getEmail()));
             message.setSubject("New contact message " + contactForm.getTopic());
             message.setReplyTo(contactForm.getEmail());
             message.setSentDate(new Date());
             Map model = new HashMap();	             
             model.put("newMessage", contactForm);
             
             String text = VelocityEngineUtils.mergeTemplateIntoString(
                velocityEngine, "velocity/newContactMessageToAdmin.vm", "UTF-8", model);
             message.setText(text, true);
          }
       };
       this.mailSender.send(preparator);	  
}
 
开发者ID:PodcastpediaOrg,项目名称:podcastpedia-web,代码行数:22,代码来源:EmailNotificationServiceImpl.java

示例5: sendSuggestPodcastNotification

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public void sendSuggestPodcastNotification(final SuggestedPodcast suggestedPodcast) {
      MimeMessagePreparator preparator = new MimeMessagePreparator() {
	        @SuppressWarnings({ "rawtypes", "unchecked" })
			public void prepare(MimeMessage mimeMessage) throws Exception {
	             MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
	             message.setTo(configService.getValue("EMAIL_TO_SUGGEST_PODCAST"));
	             message.setBcc("[email protected]");
	             message.setFrom(new InternetAddress(suggestedPodcast.getEmail()) );
	             message.setSubject("New suggested podcast");
	             message.setSentDate(new Date());
	             Map model = new HashMap();	             
	             model.put("newPodcast", suggestedPodcast);		             
	             String text = VelocityEngineUtils.mergeTemplateIntoString(
	                velocityEngine, "velocity/suggestPodcastNotificationMessage.vm", "UTF-8", model);
	             message.setText(text, true);
	          }
	       };
	       mailSender.send(preparator);			
}
 
开发者ID:PodcastpediaOrg,项目名称:podcastpedia-web,代码行数:20,代码来源:EmailNotificationServiceImpl.java

示例6: send

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void send(final String title, final String text, final List<String> recipients) {
    MimeMessagePreparator preparator = mimeMessage -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
        message.setTo(toInternetAddresses(recipients));
        message.setFrom(properties.getProperty("sender"));
        message.setSubject(title);
        message.setSentDate(new Date());

        message.setText(text, true);
    };
    LOGGER.debug("send mail with title: {}", title);
    mailSender.send(preparator);
}
 
开发者ID:voyages-sncf-technologies,项目名称:cerebro,代码行数:15,代码来源:MailSenderImpl.java

示例7: prepare

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
@Override
public void prepare(MimeMessage mimeMessage)
        throws MessagingException, UnsupportedEncodingException {
    MimeMessageHelper message = new MimeMessageHelper(mimeMessage, ENCODING);
    // set some headers to avoid automatic OutOfOffice replies
    mimeMessage.setHeader("Precedence", "list");
    mimeMessage.setHeader("X-Auto-Response-Suppress", "OOF");
    String identifier = mailMessage.getMessageIdentifier();
    if (identifier != null) {
        mimeMessage.setHeader(HEADER_MESSAGE_ID,
                MailMessageHelper.createMessageIdHeaderValue(identifier));
    }
    // set before as default, the velocity engine may overwrite this
    message.setFrom(mailMessage.getFromAddress(), mailMessage.getFromAddressName());
    message.setSentDate(new Date());

    String replyTo = mailMessage.getReplyToAddress();
    String replyToName = mailMessage.getReplyToAddressName();
    if (!StringUtils.isBlank(replyTo)) {
        message.setReplyTo(replyTo, replyToName);
    }

    // get global model
    Map<String, Object> model = mailMessage.getGlobalModel();
    mailMessage.prepareModel(model);
    model.put(MailModelPlaceholderConstants.MESSAGE, message);

    String text = renderVelocityTemplate(mailMessage.getContentTemplateId(),
            mailMessage.getContentTemplate(), model);
    message.setText(text, mailMessage.isHtmlMail());
    String subject = renderVelocityTemplate(mailMessage.getSubjectTemplateId(),
            mailMessage.getSubjectTemplate(), model);
    message.setSubject(subject);
    setRecipients(message);
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:36,代码来源:VelocityMimeMessagePreparator.java

示例8: getMimeMessage

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private MimeMessage getMimeMessage(String fromAddress, String toAddress, String subject, String mailContent) {
    final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
    final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
    try {
        message.setFrom(fromAddress);
        message.setTo(toAddress);
        message.setSubject(subject);
        message.setText(mailContent, true);
        message.setSentDate(new Date());
    } catch (MessagingException e) {
        throw new SendEmailException("Could not create metadata for email", e);
    }
    return mimeMessage;
}
 
开发者ID:osiam,项目名称:addon-administration,代码行数:15,代码来源:EmailSender.java

示例9: createMessagePreperator

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
private MimeMessagePreparator createMessagePreperator(Mail mail) {
    MimeMessagePreparator preparator = (MimeMessage mimeMessage) -> {
        MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
        message.setTo(mail.getRecipients());
        message.setFrom(new InternetAddress("[email protected]"));
        message.setSubject(mail.getSubject());
        message.setSentDate(new Date());
        message.setText(mail.getMessage(), true);
    };
    return preparator;
}
 
开发者ID:dma-graveyard,项目名称:MaritimeCloudPortalTestbed,代码行数:12,代码来源:SmtpMailAdapter.java

示例10: assmbleMimeHelper

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/** 组装需要的参数 */
private MimeMessageHelper assmbleMimeHelper(MimeMessage mimeMessage, String to, String subject) throws MessagingException {
	MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, MimeMessageHelper.MULTIPART_MODE_MIXED_RELATED);
	helper.setFrom(this.getFrom());
	helper.setTo(to);
	helper.setSentDate(new Date());
	helper.setSubject(subject);
	return helper;
}
 
开发者ID:duomn10,项目名称:spring-usage,代码行数:10,代码来源:MailSenderImpl.java

示例11: sendActivationEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/** 
 * {@inheritDoc}
 * @see com.mobileman.projecth.business.MailManager#sendActivationEmail(User, String)
 */
@Override
public void sendActivationEmail(final User user, final String serverDnsName) {
	if (log.isDebugEnabled()) {
		log.debug("sendActivationEmail(" + user + ", " + serverDnsName + ") - start");
	}
	
	MimeMessagePreparator preparator = new MimeMessagePreparator() {
        
		/**
		 * {@inheritDoc}
		 * @see org.springframework.mail.javamail.MimeMessagePreparator#prepare(javax.mail.internet.MimeMessage)
		 */
		@Override
           public void prepare(MimeMessage mimeMessage) throws Exception {
			if (log.isDebugEnabled()) {
				log.debug("$MimeMessagePreparator.prepare(MimeMessage) - start"); //$NON-NLS-1$
			}

			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, EMAIL_ENCODING);
			messageHelper.setSentDate(new Date());				
			messageHelper.setTo(user.getUserAccount().getEmail());
			messageHelper.setFrom("[email protected]");
			messageHelper.setSubject("Ihre Anmeldung bei projecth®");
			
			String tmpServerDnsName = serverDnsName;
               if (tmpServerDnsName == null || tmpServerDnsName.trim().length() == 0) {
               	tmpServerDnsName = "projecth.de";
               }
               
               Map<String, Object> model = new HashMap<String, Object>();
               model.put("user", user);
               model.put("dns_server_name", tmpServerDnsName);
               
               String htmlMessage = VelocityEngineUtils.mergeTemplateIntoString(
                  velocityEngine, "sign-up-activation-email-body.vm", model);
               String textMessage = HTMLTextParser.htmlToText(htmlMessage);
               messageHelper.setText(textMessage, htmlMessage);
                
               if (log.isDebugEnabled()) {
				log.debug("$MimeMessagePreparator.prepare(MimeMessage) - returns"); //$NON-NLS-1$
			}
           }
       };
       
       this.mailSender.send(preparator); 
       
	if (log.isDebugEnabled()) {
		log.debug("sendActivationEmail(User) - returns"); //$NON-NLS-1$
	}
}
 
开发者ID:MobileManAG,项目名称:Project-H-Backend,代码行数:55,代码来源:MailManagerImpl.java

示例12: sendResetCredientialsEmail

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/** 
 * {@inheritDoc}
 * @see com.mobileman.projecth.business.MailManager#sendResetCredientialsEmail(User, String)
 */
@Override
public void sendResetCredientialsEmail(final User user, final String serverDnsName) {
	if (log.isDebugEnabled()) {
		log.debug("sendResetCredientialsEmail(" + user.getId() + ", " + serverDnsName + ") - start");
	}
	
	MimeMessagePreparator preparator = new MimeMessagePreparator() {
        			
		@Override
           public void prepare(MimeMessage mimeMessage) throws Exception {
			if (log.isDebugEnabled()) {
				log.debug("$MimeMessagePreparator.prepare(MimeMessage) - start"); //$NON-NLS-1$
			}

			MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, EMAIL_ENCODING);
			messageHelper.setSentDate(new Date());				
			messageHelper.setTo(user.getUserAccount().getEmail());
			messageHelper.setFrom("[email protected]");
			messageHelper.setSubject("Passwort zurücksetzen");
			
			String tmpServerDnsName = serverDnsName;
               if (tmpServerDnsName == null || tmpServerDnsName.trim().length() == 0) {
               	tmpServerDnsName = "projecth.de";
               }
               
			Map<String, Object> model = new HashMap<String, Object>();
               model.put("user", user);
               model.put("dns_server_name", tmpServerDnsName);
               
               String htmlMessage = VelocityEngineUtils.mergeTemplateIntoString(
                  velocityEngine, "reset-credentials-email-body.vm", model);
               String textMessage = HTMLTextParser.htmlToText(htmlMessage);
               messageHelper.setText(textMessage, htmlMessage);

			if (log.isDebugEnabled()) {
				log.debug("$MimeMessagePreparator.prepare(MimeMessage) - returns"); //$NON-NLS-1$
			}
           }
       };
       
       this.mailSender.send(preparator);
       
       if (log.isDebugEnabled()) {
		log.debug("sendResetCredientialsEmail(" + user.getId() + ") - end");
	}
}
 
开发者ID:MobileManAG,项目名称:Project-H-Backend,代码行数:51,代码来源:MailManagerImpl.java

示例13: sendMessage

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
/** 
 * {@inheritDoc}
 * @see com.mobileman.projecth.business.MailManager#sendMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 */
@Override
public void sendMessage(final String senderEmail, final String receiverEmail,
		final String subject, final String body) {
	if (log.isDebugEnabled()) {
		log.debug("sendMessage(" + senderEmail + ", " + receiverEmail + ", " + subject + ", " + body + ") - start");
	}
	
	MimeMessagePreparator preparator = new MimeMessagePreparator() {
        
		/**
		 * {@inheritDoc}
		 * @see org.springframework.mail.javamail.MimeMessagePreparator#prepare(javax.mail.internet.MimeMessage)
		 */
           @Override
		public void prepare(MimeMessage mimeMessage) throws Exception {
			if (log.isDebugEnabled()) {
				log.debug("$MimeMessagePreparator.prepare(MimeMessage) - start"); //$NON-NLS-1$
			}
			
           	MimeMessageHelper messageHelper = new MimeMessageHelper(mimeMessage, true, EMAIL_ENCODING);
			messageHelper.setSentDate(new Date());
			messageHelper.setSubject(subject);            	
			messageHelper.setTo(receiverEmail);
			
               if (senderEmail == null || senderEmail.trim().length() == 0) {
               	messageHelper.setFrom("[email protected]");
               } else {
               	messageHelper.setFrom(senderEmail);
               }
               
               String textMessage = HTMLTextParser.htmlToText(body);
               messageHelper.setText(textMessage, body);

			if (log.isDebugEnabled()) {
				log.debug("$MimeMessagePreparator.prepare(MimeMessage) - returns"); //$NON-NLS-1$
			}
           }
       };
       
       this.mailSender.send(preparator);
       
       if (log.isDebugEnabled()) {
		log.debug("sendMessage(...) - end");
	}
}
 
开发者ID:MobileManAG,项目名称:Project-H-Backend,代码行数:50,代码来源:MailManagerImpl.java

示例14: send

import org.springframework.mail.javamail.MimeMessageHelper; //导入方法依赖的package包/类
public boolean send(final EmailAddress from, final EmailAddress replyTo, final EmailContent content,
    final EmailAddress to, final EmailAddress... tos) {

    List<EmailAddress> emailTos = new ArrayList<EmailAddress>();
    emailTos.add(to);

    if (is.notEmpty(tos)) {
        emailTos.addAll(Arrays.asList(tos));
    }

    final List<InternetAddress> addressesTo = new Converter().list(emailTos,
        new Convertable<EmailAddress, InternetAddress>() {
            @Override
            public InternetAddress convert(EmailAddress in) {
                try {
                    return new InternetAddress(in.getAddress(), in.getName());
                } catch (UnsupportedEncodingException e) {
                    log.error("Error creating InternetAddress:" + e, e);
                    throw new IllegalArgumentException("Error creating InternetAddress", e);
                }
            }
        });

    MimeMessagePreparator preparator = new MimeMessagePreparator() {
        @Override
        public void prepare(MimeMessage mimeMessage) throws Exception {
            MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
            helper.setTo(addressesTo.toArray(new InternetAddress[addressesTo.size()]));
            helper.setSubject(content.getSubject());
            helper.setFrom(from.getAddress(), from.getName());
            helper.setSentDate(new Date());
            helper.setReplyTo(replyTo.getAddress(), replyTo.getName());
            helper.setText(content.getHtmlContent(), true);
        }
    };
    // é usado um try catch para poder continuar com o processo mesmo que o
    // email gere um erro
    try {
        log.info("Sending email to:" + emailTos);
        mailSender.send(preparator);
        return true;
    } catch (Exception ex) {
        log.error("Error sending email to:" + emailTos, ex);
        return false;
    }
}
 
开发者ID:celiosilva,项目名称:csa,代码行数:47,代码来源:EmailManagerImpl.java


注:本文中的org.springframework.mail.javamail.MimeMessageHelper.setSentDate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。