Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

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(""));
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
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic