• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

google app engine, issues sending email attachment

Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody

I am having issues sending email with an attachment using google app engine javamail api. Without the attachment it works fine, but with the attachment the mail is not delivered, and also there are no exceptions. Please let me no if there are any changes that need to be done to the below code.

try {

Multipart mp = new MimeMultipart();
File file= new File("example.pdf");
FileInputStream fin = new FileInputStream(file);
attachmentData = new byte[(int)file.length()];

MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(emailHtml, "text/html");

MimeBodyPart attachment = new MimeBodyPart();
// attachment.setContent(attachmentData, "application/html");
DataSource src = new ByteArrayDataSource(attachmentData, "application/pdf");
attachment.setDataHandler(new DataHandler(src));

Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("example@gmail.com"));
new InternetAddress(req.getParameter("email"), "Mr. User"));
msg.setSubject("Email Testing By example");
System.out.println("I am above Transport.send(msg)");

} catch (Exception e) {

req.setAttribute("ERRORMESSAGE", "Error while sending email");


Any help is appreciated.

Praveen Sangolli
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody
Figured out what was the issue. The code is all working. It was my mistake, i thought the attachment should not exceed 1MB, but its the message with the attachment that should not exceed 1MB.. Now that i reduced the size of the attachment its all working fine. Sorry to bother you all.

Thanks & Regards
Praveen N Sangolli
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic