Search in sources :

Example 1 with MimeMailMessage

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());
}
Also used : MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage)

Example 2 with MimeMailMessage

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());
}
Also used : MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage)

Example 3 with MimeMailMessage

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;
}
Also used : MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MailMessage(org.springframework.mail.MailMessage) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MailMessage(org.springframework.mail.MailMessage) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMessage(javax.mail.internet.MimeMessage) Message(org.springframework.messaging.Message) SimpleMailMessage(org.springframework.mail.SimpleMailMessage) MimeMessage(javax.mail.internet.MimeMessage) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Example 4 with MimeMailMessage

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);
    }
}
Also used : MessageMappingException(org.springframework.integration.mapping.MessageMappingException) MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) ByteArrayResource(org.springframework.core.io.ByteArrayResource) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper)

Example 5 with MimeMailMessage

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);
    }
}
Also used : MimeMailMessage(org.springframework.mail.javamail.MimeMailMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) MessagingException(javax.mail.MessagingException) MessageMappingException(org.springframework.integration.mapping.MessageMappingException) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Aggregations

MimeMailMessage (org.springframework.mail.javamail.MimeMailMessage)6 MimeMessage (javax.mail.internet.MimeMessage)3 MessagingException (javax.mail.MessagingException)2 MessageMappingException (org.springframework.integration.mapping.MessageMappingException)2 JavaMailSender (org.springframework.mail.javamail.JavaMailSender)2 MessageHandlingException (org.springframework.messaging.MessageHandlingException)2 InternetAddress (javax.mail.internet.InternetAddress)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 MailMessage (org.springframework.mail.MailMessage)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 MimeMessageHelper (org.springframework.mail.javamail.MimeMessageHelper)1 Message (org.springframework.messaging.Message)1