从java程序打开outlook邮件并将文件附加到目录中的邮件

我需要在我的Java应用程序中实现电子邮件function,这将打开microsoft outlook并从我的目录中附加文件。 有没有实现相同的?

根据这些文档 ,您需要的命令是

"path/to/Outlook.exe /c ipm.note /a \"path/to/attachment\"" 

组装它并通过ProcessBuilder运行它

(或者听听MarcoS,他给出了一个非常好的例子,说明为什么有时候最好不要回答问题:-))

您可以使用桌面类打开系统的电子邮件客户端。

 Desktop.getDesktop().mail( new URI( "mailto:address@somewhere.com" ) ) 

如果要在Java中实现电子邮件function,请考虑使用JavaMail 。 此外,如果您的应用程序具有电子邮件function,则您无需打开另一个电子邮件客户端(例如outlook)。

这是你想要的确切命令: –

 new ProcessBuilder("C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe","/a","C:\\Desktop\\stackoverflow.txt").start(); 

第一个论点 – Outlook的路径。

Second Argument- Outlook附件命令。

第三个论点 – 附件路径

我已经能够使用HTML电子邮件打开MS Outlook 2007。 我使用SWT OLE API完成了这个。 这是关于Vogela的教程: http ://www.vogella.com/articles/EclipseMicrosoftIntegration/article.html

它在教程中说它也适用于非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" */); }