1 17 package org.apache.servicemix.components.email; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.messaging.MessageExchange; 21 import javax.jbi.messaging.NormalizedMessage; 22 23 import org.apache.servicemix.components.util.OutBinding; 24 import org.springframework.mail.MailSender; 25 import org.springframework.mail.SimpleMailMessage; 26 27 32 public class SimpleMailSender extends OutBinding { 33 private MailSender sender; 34 private SimpleMailMarshaler marshaler = new SimpleMailMarshaler(); 35 36 public MailSender getSender() { 39 return sender; 40 } 41 42 public void setSender(MailSender sender) { 43 this.sender = sender; 44 } 45 46 public SimpleMailMarshaler getMarshaler() { 47 return marshaler; 48 } 49 50 public void setMarshaler(SimpleMailMarshaler marshaler) { 51 this.marshaler = marshaler; 52 } 53 54 protected void init() throws JBIException { 57 super.init(); 58 if (sender == null) { 59 throw new JBIException("You must configure the sender property"); 60 } 61 } 62 63 protected void process(final MessageExchange exchange, final NormalizedMessage message) throws Exception { 64 SimpleMailMessage email = new SimpleMailMessage(); 65 marshaler.prepareMessage(email, exchange, message); 66 sender.send(email); 67 done(exchange); 68 } 69 } 70 | Popular Tags |