use of org.springframework.mail.javamail.MimeMessageHelper in project jprime by bgjug.
the class MailService method sendInvoice.
public void sendInvoice(String to, String subject, String messageText, byte[] pdf, String pdfFilename) throws MessagingException {
ByteArrayResource bais = null;
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true);
helper.setFrom(emailAddress);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(messageText, true);
bais = new ByteArrayResource(pdf);
helper.addAttachment(pdfFilename, bais);
mailSender.send(mimeMessage);
}
use of org.springframework.mail.javamail.MimeMessageHelper in project Gatekeeper by FINRAOS.
the class EmailService method generateMimeMessage.
private MimeMessage generateMimeMessage(String to, String from, String cc, String subject) throws MessagingException {
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, charset);
InternetAddress fAddress = new InternetAddress(from);
message.setTo(InternetAddress.parse(to, true));
if (cc != null) {
message.setCc(InternetAddress.parse(cc, true));
}
message.setFrom(fAddress);
message.setSubject(subject);
return mimeMessage;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project Gatekeeper by FINRAOS.
the class EmailService method sendEmailWithAttachment.
/**
* Generates and sends an email
*
* @param to - Comma separated list of users to send email
* @param cc - Comma separated list of users to cc
* @param emailSubject - String containing subject of email
* @param template - Template name for email
* @param contentMap - Key-value pairing used by template
* @param attachmentName - Name of attachment
* @param attachmentTemplate - Template name for email attachment
* @param attachmentMap - Key-value pairing used by attachment template
* @return - the mimeMessage object
* @throws Exception
*/
public MimeMessage sendEmailWithAttachment(String to, String from, String cc, String emailSubject, String template, Map<String, Object> contentMap, String attachmentName, String attachmentTemplate, Map<String, Object> attachmentMap, String mimeType) throws Exception {
logger.info("Sending email to " + to + " with subject " + emailSubject + " and message: " + template);
MimeMessage mimeMessage = generateMimeMessage(to, from, cc, emailSubject);
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true, charset);
message.setText(generateEmailMessage(template, contentMap), true);
if (attachmentName != null) {
DataSource data = new ByteArrayDataSource(generateEmailMessage("attachments/" + attachmentTemplate, attachmentMap), mimeType);
message.addAttachment(attachmentName, data);
}
javaMailSender.send(mimeMessage);
return mimeMessage;
}
use of org.springframework.mail.javamail.MimeMessageHelper in project xm-ms-entity by xm-online.
the class MailService method sendEmail.
// package level for testing
void sendEmail(String to, String subject, String content, String from) {
log.debug("Send email[multipart '{}' and html '{}'] to '{}' with subject '{}' and content={}", false, true, to, subject, content);
// Prepare message using a Spring helper
MimeMessage mimeMessage = javaMailSender.createMimeMessage();
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, false, CharEncoding.UTF_8);
message.setTo(to);
message.setFrom(from);
message.setSubject(subject);
message.setText(content, true);
javaMailSender.send(mimeMessage);
log.debug("Sent email to User '{}'", to);
} catch (Exception e) {
if (log.isDebugEnabled()) {
log.warn("Email could not be sent to user '{}'", to, e);
} else {
log.warn("Email could not be sent to user '{}': {}", to, e.getMessage());
}
}
}
use of org.springframework.mail.javamail.MimeMessageHelper in project Spring-Family by Sierou-Java.
the class MainServiceImpl method sendAttachmentsMail.
@Override
public Boolean sendAttachmentsMail(String to, String subject, String content, String filePath) {
Boolean flag = false;
MimeMessage message = mailSender.createMimeMessage();
try {
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);
mailSender.send(message);
logger.info("带附件的邮件已经发送。");
} catch (MessagingException e) {
logger.error("发送带附件的邮件时发生异常!", e);
}
return flag;
}
Aggregations