Reputation: 33
In Java, how to launch the mail client along with the given file as its attachment - particularly using the method Desktop.getDesktop().mail(URI)
I am using Windows 7 and want to launch MS Outlook.
Upvotes: 2
Views: 1769
Reputation: 116
As far as I know, it is unfortunatly not possible to specify any attachment using Desktop.mail(URI)
.
I've tried AlexR suggestion. It doesn't work if the file is too big because of the restriction of the number of characters in the URI.
However, it is still possible using JMAPI, though it only works on x86 platforms.
The ultimate way to make it work is using the JavaMail API, but it forces you to create your own GUI and to set the SMTP server configuration.. which is not pretty user-friendly.
If anyone as other suggestions, i'd be glad to know them.
Upvotes: 0
Reputation: 115328
It is a good question.
Indeed the URI
that sent as a parameter to method desktop.mail(URI)
allows setting to, cc, bcc, subject, body and does not allow setting attachments. (see http://www.ietf.org/rfc/rfc2368.txt)
However attachments are actually specially formatted fragments of email body. Please read this for more details: http://techhelp.santovec.us/decode.htm. This means that you can encode your binary attachment using Base64 and create email body that already contains the attachment of any generic file. I personally have not tried this but I believe it must work. Good luck.
Upvotes: 2