GAE attaching PNG image to an email

0 views
Skip to first unread message

Marek via StackOverflow

unread,
Mar 18, 2014, 6:05:34 AM3/18/14
to google-appengin...@googlegroups.com

I would like to attach a png image file to an email message on GAE. At the beginning I started from:

MimeMessage msg = new MimeMessage(session);
... 
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.attachFile("/templates/header_nr1.png");
...
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(textPart);
multipart.addBodyPart(htmlPart);
multipart.addBodyPart(imagePart); 

But this caused

pl.insert.services.ExceptionHandler handleUnknownException:java.security.AccessControlException:access denied ("java.io.FilePermission" "/templates/header_nr1.png" "read")

and many other variations about that which I was not able to solve by using any of the available solutions.

According to https://developers.google.com/appengine/docs/java/mail/usingjavamail#Multi_Part_Messages I have changed the way of retrieving the file to:

InputStream fileIs = MailServiceImpl.class.getResourceAsStream("/templates/header_nr1.png");
byte[] headerImage = IOUtils.toByteArray(fileIs);

String cid = "header_nr1";
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setFileName("header_nr1.png");
DataSource src = new ByteArrayDataSource(headerImage, "image/png");
imagePart.setDataHandler(new DataHandler(src));
imagePart.setContent(headerImage, "image/png");
imagePart.setContentID("<" + cid + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);

Now I have

javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Converting attachment data failed)
at javax.mail.Transport.send(Transport.java:163)
at javax.mail.Transport.send(Transport.java:48)

Could anyone help me with the problem ? :(



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/22475752/gae-attaching-png-image-to-an-email
Reply all
Reply to author
Forward
0 new messages