You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Sandhu <ka...@gmail.com> on 2006/03/13 04:49:51 UTC
MimeMailSender - Attachments howto?
Hi all,
Trying to get attachment mails sent through enhancing mimeMailSender
component and could get it working as below -
1. Component A creates attachment and sends it through normalized
message into SM using- message.addAttachment(name,dataHandler).
2. The mailSender BC receives it and creates mail with attachment
using Spring's MimeMessageHelper -
helper.addAttachment(name,byteArrayResource).
It works but this doesn't smell right (ReCreating a BAOS thru this
read-write procedure in MailMarshaller again):
ByteArrayOutputStream stream = new ByteArrayOutputStream();
BufferedOutputStream out = new BufferedOutputStream(stream);
try { //
io (normalizedMessage.getAttachment(name).getInputStream(),out);
out.close ();
} catch (Exception e) {
e.printStackTrace ();
}
byte[] bytes = stream.toByteArray();
ByteArrayResource bbs = new ByteArrayResource(bytes);
helper.addAttachment(name,bbs);
//read-write procedure
public static void io (InputStream in, OutputStream out)
throws IOException {
byte[] buffer = new byte[8192];
int amount;
while ((amount = in.read (buffer)) >= 0)
out.write (buffer, 0, amount);
}
Can anyone advise how to better get attachment transported in SM as
helper.addAttachment( name, DataHandler) does not work (multiple reads
reqd ?)
Rgds,
Sandhu