I need to implement Email functionality in my Java application which will open microsoft outlook and attach a file from my directory. Has any implemented the same?
5 Answers
According to these docs the command you need is
"path/to/Outlook.exe /c ipm.note /a \"path/to/attachment\""
Assemble this and run it via ProcessBuilder
(Or listen to MarcoS who gives a very good example of why it's sometimes better not to literally answer questions :-))

- 292,901
- 67
- 465
- 588
If you want to implement email functionalities in Java, consider JavaMail. Also, if your application has email functionalities, then you don't need to open another email client (such as outlook).

- 13,386
- 7
- 42
- 63
-
It is ok for a server side application or for some specific use-cases on desktop, but in general, you need SMTP server to send an e-mail. And not many users (statistically, noone) runs it on their local computer. You can use remote SMTP server, but even if you build all support to bypass firewalls and other obstacles, you don't want to do it, as spammers will eat it as an easy lunch. – serg.nechaev Aug 15 '14 at 05:08
-
1@serg.nechaev you need a mail server (SMTP, Exchange, Domino, whatever) in any case to send an email :) – MarcoS Aug 26 '14 at 12:25
I have been able to Open MS Outlook 2007 with a HTML email. I have done this using SWT OLE API. Here's the tutorial on Vogela: http://www.vogella.com/articles/EclipseMicrosoftIntegration/article.html
It says in tutorial that it also works for non-RCP Java.
public void sendEMail()
{
OleFrame frame = new OleFrame(getShell(), SWT.NONE);
// This should start outlook if it is not running yet
OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");
site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
// Now get the outlook application
OleClientSite site2 = new OleClientSite(frame, SWT.NONE, "Outlook.Application");
OleAutomation outlook = new OleAutomation(site2);
OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */).getAutomation();
setProperty(mail, "BodyFormat", 2 /* HTML */);
setProperty(mail, "Subject", subject);
setProperty(mail, "HtmlBody", content);
if (null != attachmentPaths)
{
for (String attachmentPath : attachmentPaths)
{
File file = new File(attachmentPath);
if (file.exists())
{
OleAutomation attachments = getProperty(mail, "Attachments");
invoke(attachments, "Add", attachmentPath);
}
}
}
invoke(mail, "Display" /* or "Send" */);
}
-
1This kind of answer is more useful to the community when you provide an exerpt from the article, in addition to the link. At some point in the future, that link may not be working - and someone finding this answer would then be stuck again. – Troy Alford Nov 29 '12 at 21:58
Here is the exact command you want:-
new ProcessBuilder("C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe","/a","C:\\Desktop\\stackoverflow.txt").start();
First Argument-Path to Outlook.
Second Argument- Outlook attachment command.
Third Argument- Attachment path

- 1,220
- 3
- 15
- 37