Search in sources :

Example 1 with MailMessage

use of org.springframework.mail.MailMessage 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)

Aggregations

MimeMessage (javax.mail.internet.MimeMessage)1 MailMessage (org.springframework.mail.MailMessage)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1 MimeMailMessage (org.springframework.mail.javamail.MimeMailMessage)1 Message (org.springframework.messaging.Message)1 MessageHandlingException (org.springframework.messaging.MessageHandlingException)1