• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail with Attachments

Dave Wingate
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know of a good tutorial discussing how to send JavaMail with attachments. Particularly, I'm trying to send an email with a pdf attachment. The PDF is an in-memory stream.

Also, do I need to worry about using MIMEUtility encoding methods? I don't really understand why I would have to "encode" my pdf stream or what character set I would have to encode it into. Does anyone know of a good explanation of this topic?

I've found some info on JGuru and have tried to use this code:

But this code is throwing a parse exception:

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)
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic