1 17 package org.apache.servicemix.components.email; 18 19 import org.apache.servicemix.components.util.OutBinding; 20 import org.springframework.mail.javamail.JavaMailSender; 21 import org.springframework.mail.javamail.MimeMessagePreparator; 22 23 import javax.jbi.JBIException; 24 import javax.jbi.messaging.MessageExchange; 25 import javax.jbi.messaging.NormalizedMessage; 26 import javax.mail.MessagingException ; 27 import javax.mail.internet.MimeMessage ; 28 29 35 public class MimeMailSender extends OutBinding { 36 private JavaMailSender sender; 37 private MimeMailMarshaler marshaler = new MimeMailMarshaler(); 38 39 public JavaMailSender getSender() { 42 return sender; 43 } 44 45 public void setSender(JavaMailSender sender) { 46 this.sender = sender; 47 } 48 49 public MimeMailMarshaler getMarshaler() { 50 return marshaler; 51 } 52 53 public void setMarshaler(MimeMailMarshaler marshaler) { 54 this.marshaler = marshaler; 55 } 56 57 58 protected void init() throws JBIException { 61 super.init(); 62 if (sender == null) { 63 throw new JBIException("You must configure the sender property"); 64 } 65 } 66 67 protected void process(final MessageExchange exchange, final NormalizedMessage message) throws Exception { 68 MimeMessagePreparator preparator = new MimeMessagePreparator() { 69 public void prepare(MimeMessage mimeMessage) throws MessagingException { 70 marshaler.prepareMessage(mimeMessage, exchange, message); 71 } 72 }; 73 sender.send(preparator); 74 done(exchange); 75 } 76 } 77 | Popular Tags |