use of org.springframework.mail.javamail.MimeMessageHelper in project CBEC-B2B by A-Cubic.
the class EmailUtils method sendNormalEmail.
/**
* 发送邮件
*
* @param title
* 标题
* @param titleWithName
* 是否在标题后添加 名称
* @param content
* 内容
* @param contentWithName
* 是否在内容后添加 名称
* @param email
* 接收者的邮箱【注册人】
*/
@Async
private void sendNormalEmail(String title, boolean titleWithName, String content, boolean contentWithName, String email) {
String dName = "流连优选";
MimeMessage mimeMessage = null;
try {
// 创建要发送的信息
mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
// 设置 谁发送的
helper.setFrom(new InternetAddress(username, dName, "UTF-8"));
// 发给谁 【接收者的邮箱】
helper.setTo(email);
// 标题内容
title = titleWithName ? title + "-" + dName : title;
// 发送邮件的辩题
helper.setSubject(title);
if (contentWithName) {
content += "<p style='text-align:right'>" + dName + "</p>";
content += "<p style='text-align:right'>" + Util.curDate("yyyy-MM-dd HH:mm:ss") + "</p>";
}
// 发送的内容 是否为html
helper.setText(content, true);
} catch (Exception e) {
e.printStackTrace();
}
javaMailSender.send(mimeMessage);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project free-framework by a601942905git.
the class EmailService method sendHtmlMail.
/**
* 发送html格式的邮件
* @param to
* @param subject
* @param content
*/
public void sendHtmlMail(String to, String subject, String content) {
MimeMessage message = sender.createMimeMessage();
try {
// true表示需要创建一个multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(content, true);
sender.send(message);
log.info("html邮件已经发送。");
} catch (MessagingException e) {
log.error("发送html邮件时发生异常!", e);
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project free-framework by a601942905git.
the class EmailService method sendAttachmentsMail.
/**
* 发送带附件的邮件
* @param to
* @param subject
* @param content
* @param filePath
*/
public void sendAttachmentsMail(String to, String subject, String content, String filePath) {
MimeMessage message = sender.createMimeMessage();
try {
// true表示需要创建一个multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(from);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(content, true);
FileSystemResource file = new FileSystemResource(new File(filePath));
String fileName = filePath.substring(filePath.lastIndexOf(File.separator));
helper.addAttachment(fileName, file);
sender.send(message);
log.info("带附件的邮件已经发送。");
} catch (MessagingException e) {
log.error("发送带附件的邮件时发生异常!", e);
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project FP-PSP-SERVER by FundacionParaguaya.
the class EmailServiceImpl method sendSimpleMessage.
@Override
public void sendSimpleMessage(String to, String subject, String text) {
try {
MimeMessage mail = mailSender.createMimeMessage();
mail.setFrom(appProperties.getSender().getFrom());
MimeMessageHelper helper = new MimeMessageHelper(mail, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text, true);
mailSender.send(mail);
} catch (Exception e) {
LOG.error("Mail server connection failed ", e);
throw new CustomParameterizedException(i18n.translate("email.serverError"));
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project FP-PSP-SERVER by FundacionParaguaya.
the class EmailServiceImpl method sendMessageWithAttachment.
@Override
public void sendMessageWithAttachment(String to, String subject, String text, String pathToAttachment) {
try {
MimeMessage message = mailSender.createMimeMessage();
message.setFrom(appProperties.getSender().getFrom());
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(text);
FileSystemResource file = new FileSystemResource(new File(pathToAttachment));
helper.addAttachment("File", file);
mailSender.send(message);
} catch (MessagingException e) {
LOG.error("Error sending mail ", e);
throw new CustomParameterizedException(i18n.translate("email.errorSendingMail"));
}
}
Aggregations