This week's giveaway is in the Spring forum.
We're giving away four 3 month subscriptions to Marco Behler Videos and have Marco Behler on-line!
See this thread for details.
Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Send PDF in JavaMail  RSS feed

 
Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • 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 ]
 
Dave Boden
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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 )

 
Amit Siinngghh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try apache commons email http://jakarta.apache.org/commons/email/

-Amit
 
Seetesh Hindlekar
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
Awais Bajwa
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great work Dave..
but still I want to know what is the advantage of the following Buffering code.


Regards
 
Revanth Sharma
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • 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.
 
madhava Thamata
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!