Hi, I am using Camel-mail component to send emails out to clients for given byteOutputStream (content is html email) and imagesData in byte[] (image used in html content). ProducerTemplate.sendBodyandHeaders() has all the mail paramter details to send to client. However, I am not able to find a way where I can add image to the header which will ensure html email content can embedd the image when sending to clients. Normally, it will work with exchange.getIn().addAttchement("cid:001", dataHandler(image name)). But with ProducerTemplate I do not have way to add the attachments to Exchange.getIn() object. Even the camel-mail test classes use Exchange.getIn().addAttachement(..) and use the exchange object in ProducerTemplate. In my cases I do not create exchange object at all when using ProducerTemplate. Could you please advise how I can add attachments through ProducerTemplate?
public class EmailSender{ @Autowired private ProducerTemplate template; private void sendEmail(ByteArrayOutputStream byteArrayOutputStream ,HashMap<String,byte[]> imagesData, String to, String from) { try{ Map<String, Object> map = new HashMap<String, Object>(); map.put("To", to); map.put("From", from); map.put("Subject", "Camel rocks"); // ByteArrayDataSource bs = new ByteArrayDataSource(imagesData.get("px"),"application/octet-stream"); //map.put("cid:px", new DataHandler(bs)); template.sendBodyAndHeaders("smtp://testServer@host.mailbank?&password=test123&contentType=text/html", byteArrayOutputStream.toString(), map); }catch (Exception e){ LOG.error("Unable to send mail !!!" + e); } } } -- View this message in context: http://camel.465427.n5.nabble.com/ProducerTemplate-for-sending-mails-with-attachements-tp5605511p5605511.html Sent from the Camel - Users mailing list archive at Nabble.com.