Reputation: 9
In my application requirement to send an email with an attached file.
Just to open the outlook with new mail message having the attachment attached. rest is upto user if he sends it or not :)
I use the below code .
try {
String stLineSep; // String containing the system line separator
// Line separator:
stLineSep = System.getProperty("line.separator"); // Get it
Runtime.getRuntime().exec(
new String[] {"rundll32",
"url.dll,FileProtocolHandler",
"mailto:" + "&attachment=" + "c:\\ashish.txt"}
);//","attachment;filename="+strFileName
}
catch (Exception ex) {
ex.printStackTrace();
}
I am able to open the outlook without attachment can you please tell me how it will work with attachment. Please help Thanks in Advance
Upvotes: 0
Views: 1674
Reputation: 162
mailto: is not required to handle that (The mailto URL scheme [RFC 2368] found by http://abauchu.net/blog/post/2008/12/28/Handling-mailto-url-and-attachment-with-Gmail-from-the-desktop). One solution would be calling Outlook a bit more direct but it leads to very tight coupling: http://www.grauberger.org/wordpress/2013/07/18/e-mail-mit-anhang-ueber-die-cmd-in-outlook-oeffnen/ (language is German) which simply uses a fixed path to your Outlook client executable...
"C:\Program Files\Microsoft Office\Office14\Outlook.exe" /m "[email protected]?subject=WhateverSubjectYouWish&body=seeAttachmentOrWhatever" /a "C:\myAttachment.txt"
Upvotes: 2