Mark
Mark

Reputation: 4935

How to use the default email client to send an email with an attachment from Java?

I have a Java program which generates a PDF file. I want the user to click a button to open the default email client ready to send the PDF as an attachment. The two standard ways of opening the default email client have problems:

  1. Java 6 doesn't seem to allow for attachments in the generated message
  2. JDIC has a bug which prevents Outlook 2007 from sending the message correctly: http://jdic.dev.java.net/issues/show_bug.cgi?id=160

Can anyone suggest a way to do this?

Thanks

Upvotes: 2

Views: 2566

Answers (3)

Brian de Alwis
Brian de Alwis

Reputation: 2974

JDIC provides some functionality to do this. Although much of JDIC was absorbed into java.awt.Desktop in Java 6, it didn't include the email composition bits. Unfortunately the JDIC binaries disappeared with the transition of java.net to the Kenai platform; I uploaded the most recent versions I could find to the project JIRA.

JDIC doesn't play well in OSGi, so I recently extracted the relevant MAPI bits into a bundle called jmapi.

(I posted this answer to another question too.)

Upvotes: 2

Charlie Martin
Charlie Martin

Reputation: 112404

Did javax.mail.internet.MimeMultipart go away? That's sort of the canonical way to set up an attachment.

Update

Okay, so if I've got this straight, you want to know how to let your application use an unspecified email client on an unspecified operating system to send a multipart MIME email containing an undefined attachment but not by constructing the MIME message yourself?

... well, okay, I guess you mentioned Outlook so it must be Windows. But still.

Upvotes: 1

Jack Leow
Jack Leow

Reputation: 22497

Is there a specific reason you'd like to use the default e-mail client, rather than sent it from Java using the e-mail client (JavaMail)?

Can you provide more details as to the kind of application you're trying to write? I take it this is a client GUI application (Swing/SWT/AWT), but beyond that, I think we're going to need more details.

Upvotes: 0

Related Questions