• 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

Send PDF in JavaMail

 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have little experience with javamail and would really appreciate any help you could offer on this error. I'm trying to send a pdf (in memory) as an attachment to an email.

So far I've got:



And this helper class:




When run, I'm getting the following exception:

SMTPMailSender |javax.mail.internet.ParseException
at java.lang.Throwable.<init>(Throwable.java)
at javax.mail.MessagingException.<init>(MessagingException.java:34)
at javax.mail.internet.ContentType.<init>(ContentType.java:72)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1016)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:790)
at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:216)
at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1021)
at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:1841)
at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:1822)
at javax.mail.Transport.send(Transport.java:80)
at ct.fw.mail.SMTPMailSender.run(SMTPMailSender.java:294)
at java.lang.Thread.run(Thread.java:802)


Just before sending the message, the headers are:


Date:Fri, 15 Jul 2005 18:39:56 -0500 (CDT)
From onotreply@ptsteams.com
Reply-To onotreply@ptsteams.com
To:test@ptsteams.com
Subject:subject



Can anybody tell me what I've done wrong here?

I also noticed that the DataHandler has objectMimeType set to "multipart/mixed;
boundary="----=_Part_1_2073066384.1121471029718""

Can this be right? Is this the problem?
[ July 15, 2005: Message edited by: Dave Wingate ]
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to write your implementation of DataSource so that it returns a new instance of the InputStream every time getInputStream() is called. You have to read it into a buffer in order to do this. Here's my implementation of InputStreamDataSource which I've tested (it works )

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try apache commons email http://jakarta.apache.org/commons/email/

-Amit
 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

Has anyone worked on SearchTerm?

Rgds,

Seetesh
 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brilliant. Buffering the inputstream worked for me as well. Thanks for your help. I've been beating my head against the monitor for quite a while on this one.
[ October 10, 2005: Message edited by: Dave Wingate ]
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great work Dave..
but still I want to know what is the advantage of the following Buffering code.


Regards
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to implement something similar to this. Does this work for xls files and doc files or does it mess the format.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I have same requriement like to attache the PDF in mail with out saving in local.
could any body provide some info about my requirement.

Thanks,
Madhava.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic