• 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 ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

google app engine, issues sending email attachment

 
Greenhorn
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()];
fin.read(attachmentData);

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

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

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

} catch (Exception e) {

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

}

Any help is appreciated.

 
Praveen Sangolli
Greenhorn
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic