use of org.springframework.mail.javamail.MimeMailMessage in project cshop by erafaelmanuel.
the class RegisterListener method sendConfirmRegistration.
private void sendConfirmRegistration(Token token, String url, Locale locale) {
MimeMailMessage mimeMailMessage = confirmationMail.constructMail(token, url, locale);
confirmationMail.getMailSender().send(mimeMailMessage.getMimeMessage());
}
use of org.springframework.mail.javamail.MimeMailMessage in project cshop by erafaelmanuel.
the class ResendListener method sendConfirmRegistration.
private void sendConfirmRegistration(Token token, String url, Locale locale) {
MimeMailMessage mimeMailMessage = confirmationMail.constructMail(token, url, locale);
confirmationMail.getMailSender().send(mimeMailMessage.getMimeMessage());
}
use of org.springframework.mail.javamail.MimeMailMessage in project spring-integration by spring-projects.
the class MailSendingMessageHandler method convertMessageToMailMessage.
@SuppressWarnings("unchecked")
private MailMessage convertMessageToMailMessage(Message<?> message) {
MailMessage mailMessage = null;
Object payload = message.getPayload();
if (payload instanceof MimeMessage) {
mailMessage = new MimeMailMessage((MimeMessage) payload);
} else if (payload instanceof MailMessage) {
mailMessage = (MailMessage) payload;
} else if (payload instanceof byte[]) {
mailMessage = this.createMailMessageFromByteArrayMessage((Message<byte[]>) message);
} else if (payload instanceof String) {
String contentType = (String) message.getHeaders().get(MailHeaders.CONTENT_TYPE);
if (StringUtils.hasText(contentType)) {
mailMessage = this.createMailMessageWithContentType((Message<String>) message, contentType);
} else {
mailMessage = new SimpleMailMessage();
mailMessage.setText((String) payload);
}
} else {
throw new MessageHandlingException(message, "Unable to create MailMessage from payload type [" + message.getPayload().getClass().getName() + "], " + "expected MimeMessage, MailMessage, byte array or String.");
}
this.applyHeadersToMailMessage(mailMessage, message.getHeaders());
return mailMessage;
}
use of org.springframework.mail.javamail.MimeMailMessage in project spring-integration by spring-projects.
the class MailSendingMessageHandler method createMailMessageFromByteArrayMessage.
private MailMessage createMailMessageFromByteArrayMessage(Message<byte[]> message) {
Assert.state(this.mailSender instanceof JavaMailSender, "this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
String attachmentFileName = message.getHeaders().get(MailHeaders.ATTACHMENT_FILENAME, String.class);
if (attachmentFileName == null) {
throw new MessageMappingException(message, "Header '" + MailHeaders.ATTACHMENT_FILENAME + "' is required when mapping a Message with a byte array payload to a MailMessage.");
}
Integer multipartMode = message.getHeaders().get(MailHeaders.MULTIPART_MODE, Integer.class);
if (multipartMode == null) {
multipartMode = MimeMessageHelper.MULTIPART_MODE_MIXED;
}
MimeMessage mimeMessage = ((JavaMailSender) this.mailSender).createMimeMessage();
try {
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, multipartMode);
helper.addAttachment(attachmentFileName, new ByteArrayResource(message.getPayload()));
return new MimeMailMessage(helper);
} catch (MessagingException e) {
throw new MessageMappingException(message, "failed to create MimeMessage", e);
}
}
use of org.springframework.mail.javamail.MimeMailMessage in project spring-integration by spring-projects.
the class MailSendingMessageHandler method createMailMessageWithContentType.
private MailMessage createMailMessageWithContentType(Message<String> message, String contentType) {
Assert.state(this.mailSender instanceof JavaMailSender, "this adapter requires a 'JavaMailSender' to send a 'MimeMailMessage'");
MimeMessage mimeMessage = ((JavaMailSender) this.mailSender).createMimeMessage();
try {
mimeMessage.setContent(message.getPayload(), contentType);
return new MimeMailMessage(mimeMessage);
} catch (Exception e) {
throw new org.springframework.messaging.MessagingException("Failed to create MimeMessage with contentType: " + contentType, e);
}
}
Aggregations