When sending multipart emails through the GAE send API, we sometimes
get the following exception:

Uncaught exception from servlet
java.lang.NoClassDefFoundError: java.awt.Component is a restricted
class. Please see the Google App Engine developer's guide for more
details.
        at
com.google.apphosting.runtime.security.shared.stub.java.awt.Component.<clinit>(Component.java)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
        at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
57)
        at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
        at java.lang.Class.newInstance0(Class.java:372)
        at java.lang.Class.newInstance(Class.java:325)
        at
javax.activation.MailcapCommandMap.getDataContentHandler(MailcapCommandMap.java:
596)
        at
javax.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:
550)
        at
javax.activation.CommandMap.createDataContentHandler(CommandMap.java:
206)
        at
javax.activation.DataHandler.getDataContentHandler(DataHandler.java:
609)
        at javax.activation.DataHandler.getContent(DataHandler.java:537)
        at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:392)
        at
com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:
225)
        at javax.mail.Transport.send(Transport.java:95)
        at javax.mail.Transport.send(Transport.java:48)

Here is how we are sending the multipart email:

Properties props = new Properties();
Session mailSession = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(mailSession);
MimeMultipart multipart = new MimeMultipart();

// first part (the html)
BodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlText, "text/html");
multipart.addBodyPart(htmlPart);

// second part (the image)
BodyPart attachmentPart = new MimeBodyPart();
attachmentPart.setFileName("screenshot.jpg");
DataSource imageSrc = new ByteArrayDataSource(image, "image/jpeg");
attachmentPart.setDataHandler(new DataHandler(imageSrc));
multipart.addBodyPart(attachmentPart);

message.setContent(multipart);
message.saveChanges();
Transport.send(message);

We are rarely using the GAE email API, so it is not a big deal for us
(most outbound emails using a 3rd party SMTP service), but just
thought that is an issue that seems important enough to be reported.
Adding a bitmap in a multipart email is a pretty standard use case.

Cheers,

Jerome

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" 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-java?hl=en.

Reply via email to