本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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$
}
}
示例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");
}
}
示例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");
}
}
示例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;
}
}