use of org.springframework.mail.javamail.MimeMessageHelper in project bamboobsc by billchen198318.
the class MailClientUtils method send.
public static void send(String from, String to, String[] cc, String[] bcc, String[] fileNames, File[] files, String subject, String text) throws MailException, Exception {
if (mailSender == null) {
throw new Exception("null mailSender!");
}
if (StringUtils.isBlank(from) || StringUtils.isBlank(to)) {
throw new Exception("from and to is required!");
}
if (fileNames != null && files != null) {
if (fileNames.length != files.length) {
throw new Exception("File parameter error!");
}
}
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true, Constants.BASE_ENCODING);
helper.setFrom(from);
helper.setTo(to.endsWith(";") ? to.substring(0, to.length() - 1) : to);
helper.setSubject(subject);
helper.setText(text, true);
if (null != cc && cc.length > 0) {
helper.setCc(cc);
}
if (null != bcc && bcc.length > 0) {
helper.setBcc(bcc);
}
for (int i = 0; fileNames != null && i < fileNames.length; i++) {
helper.addAttachment(fileNames[i], files[i]);
}
mailSender.send(message);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project uplace.es by Uplace.
the class MailService method sendEmail.
@Async
public void sendEmail(String to, String subject, String content, boolean isMultipart, boolean isHtml) throws MessagingException {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", isMultipart, isHtml, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project waltz by khartec.
the class WaltzEmailer method sendEmail.
public void sendEmail(String subject, String body, String[] to) {
Checks.checkNotEmpty(subject, "subject cannot be empty");
Checks.checkNotEmpty(body, "body cannot be empty");
Checks.checkNotEmpty(to, "to cannot be empty");
Checks.checkAll(to, StringUtilities::notEmpty, "email address cannot be empty");
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);
message.setSubject(subject);
message.setFrom(fromEmail);
message.setBcc(to);
message.addAttachment("waltz.png", IOUtilities.getFileResource("/images/waltz.png"));
message.addAttachment("client-logo", IOUtilities.getFileResource("/templates/images/client-logo.png"));
Map model = new HashMap();
model.put("body", body);
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
try (InputStreamReader templateReader = new InputStreamReader(IOUtilities.getFileResource(DEFAULT_EMAIL_TEMPLATE_LOCATION).getInputStream())) {
Template template = new Template("template", templateReader, cfg);
String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project zhcet-web by zhcet-amu.
the class EmailService method constructEmail.
private MimeMessage constructEmail(String emailAddress, String subject, String body, String[] bcc) throws MessagingException {
MimeMessage mimeMessage = sender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
helper.setText(body);
setBasicInfo(helper, senderEmail, emailAddress, subject, bcc);
return mimeMessage;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project paascloud-master by paascloud.
the class OptSendMailServiceImpl method getMimeMessage.
private MimeMessage getMimeMessage(String subject, String text, Set<String> to) {
Preconditions.checkArgument(!PubUtils.isNull(subject, text, to), "参数异常, 邮件信息不完整");
String[] toArray = setToArray(to);
Preconditions.checkArgument(PublicUtil.isNotEmpty(toArray), "请输入收件人邮箱");
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper;
try {
helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom(from);
helper.setTo(toArray);
helper.setSubject(subject);
helper.setText(text, true);
} catch (MessagingException e) {
log.error("生成邮件消息体, 出现异常={}", e.getMessage(), e);
throw new OpcBizException(ErrorCodeEnum.OPC10040005);
}
return mimeMessage;
}
Aggregations