I use the following code to attach a PDF file in email. However the
PDF content (PDF source code) is integrated into email body instead of
in a PDF attachment file . Could anyone help to figure out how to
attach a PDF file in email. Thank you very much.
InputStream is=httpConn.getInputStream();//download PDF file from
internet
ByteArrayDataSource ds = new ByteArrayDataSource(is, "application/
pdf");
MimeBodyPart attachment= new MimeBodyPart();
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Message msg = new MimeMessage(session);
attachment.setDataHandler(new DataHandler(ds));
attachment.setFileName("Report.pdf");
Multipart mp = new MimeMultipart();
mp.addBodyPart(attachment);
msg.setContent(mp);
msg.setFrom(new InternetAddress("..", ".."));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress("..",
".."));
msg.setSubject("..");
Transport.send(msg);
} catch ..
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.