It's not a secret anymore!
The moose likes Other JSE/JEE APIs and the fly likes Java Mail with Attachments Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail with Attachments" Watch "Java Mail with Attachments" New topic

Java Mail with Attachments

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
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>(
at javax.mail.MessagingException.<init>(
at javax.mail.internet.ContentType.<init>(
at javax.mail.internet.MimeBodyPart.updateHeaders(
at javax.mail.internet.MimeBodyPart.updateHeaders(
at javax.mail.internet.MimeMultipart.updateHeaders(
at javax.mail.internet.MimeBodyPart.updateHeaders(
at javax.mail.internet.MimeMessage.updateHeaders(
at javax.mail.internet.MimeMessage.saveChanges(
at javax.mail.Transport.send(

Fun programming etcetera!
I agree. Here's the link:
subject: Java Mail with Attachments
It's not a secret anymore!