Boa tarde pessoal,
Estou precisando de uma ajuda, para enviar um .pdf file anexado no email, porem esse pdf está sendo enviado por uma mensagem JMS ou in-memory, não tem arquivo físico na máquina, quando eu trato com um arquivo físico, ele envia sem problemas.
In-Memory oq acontece é que quando envio o arquivo .pdf e eu recebo um arquivo do tipo MIME application/octet-stream, porem já tentei tratar com DataHandler, ByteArrayDataSource, mas está difícil achar uma solução que de certo até agora.]
Segue código:
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) };
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("Assunto teste.");
// create and fill the first message part
MimeBodyPart bp1 = new MimeBodyPart();
bp1.setText("Texto teste.");
// create the second message part
MimeBodyPart bp2 = new MimeBodyPart();
// attach the file to the message
m_xqLog.logInformation("[ContentType]: "+prt.getContentType());
//FileDataSource fds = new FileDataSource(prt.getDataHandler()));
//DataHandler sh = new DataHandler((DataSource) prt.getDataHandler());
DataSource ds = new FileDataSource("scenario/Testepdf.pdf");
bp2.setDataHandler( new DataHandler(ds));
//bp2.setContent(prt.getContent().toString().getBytes(), prt.getContentType());
//bp2.setDataHandler(new DataHandler(new ByteArrayDataSource(prt.getContent().toString(),"application/pdf")));
bp2.setFileName("Testepdf.pdf");
// create the Multipart and add its parts to it
Multipart mp = new MimeMultipart();
mp.addBodyPart(bp1);
mp.addBodyPart(bp2);
// add the Multipart to the message
msg.setContent(mp);
// set the Date: header
msg.setSentDate(new Date());
// send the message
Transport.send(msg);
System.out.println("Email sent successfully!");
Neste cenário está funcionando certinho, porem estou precisando que o arquivo seje em memória e não físico.
Qualquer ajuda será bem vinda.
Abs,
Paulo Sampei