當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。