【发布时间】:2020-10-08 12:57:50
【问题描述】:
我需要在我的 Java 应用程序中实现电子邮件功能,这将打开 microsoft Outlook 并从我的目录中附加一个文件。有没有实现相同的?
【问题讨论】:
标签: java
我需要在我的 Java 应用程序中实现电子邮件功能,这将打开 microsoft Outlook 并从我的目录中附加一个文件。有没有实现相同的?
【问题讨论】:
标签: java
根据these docs你需要的命令是
"path/to/Outlook.exe /c ipm.note /a \"path/to/attachment\""
组装它并通过ProcessBuilder运行它
(或者听听 MarcoS 的例子,他举了一个很好的例子来说明为什么有时最好不要直接回答问题 :-))
【讨论】:
如果您想在 Java 中实现电子邮件功能,请考虑 JavaMail。此外,如果您的应用程序具有电子邮件功能,则无需打开其他电子邮件客户端(例如 Outlook)。
【讨论】:
您可以使用desktop 类打开系统的电子邮件客户端。
Desktop.getDesktop().mail( new URI( "mailto:address@somewhere.com" ) )
【讨论】:
我已经能够使用 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" */);
}
【讨论】:
这是您想要的确切命令:-
new ProcessBuilder("C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe","/a","C:\\Desktop\\stackoverflow.txt").start();
第一个参数-Outlook 的路径。
第二个参数 - Outlook 附件命令。
第三个参数 - 附件路径
【讨论】: