需要用附件打开ms outlook

我需要使用java实现以下逻辑。

– >当我点击一个按钮时,MS Outlook需要打开To,CC,Subject和附件。

我们可以使用mailto来做这个但是如果使用mailto就不能添加附件。

我需要从共享文件夹添加多个附件到MS Outlook

请帮帮我。

使用切换可以有单个附件,但我需要打开带有2+附件的Outlook,并且应该有发送按钮,以便用户可以发送邮件

使用JavaMail创建包含To,CC,Subject和附件的多部分mime消息。 然后,而不是传输消息调用saveChanges和writeTo ,并将电子邮件存储到文件系统。

有一个未记录的 /eml开关,可用于打开MIME标准格式。 例如, outlook /eml filename.eml有一个记录的/f开关,它将打开msg文件。 例如outlook /f filename.msg x-unsent可用于切换发送按钮。

这是一个让你入门的例子:

 public static void main(String[] args) throws Exception { //Create message envelope. MimeMessage msg = new MimeMessage((Session) null); msg.addFrom(InternetAddress.parse("you@foo.com")); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("support@bar.com")); msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse("manager@baz.com")); msg.setSubject("Hello Outlook"); //msg.setHeader("X-Unsent", "1"); MimeMultipart mmp = new MimeMultipart(); MimeBodyPart body = new MimeBodyPart(); body.setDisposition(MimePart.INLINE); body.setContent("This is the body", "text/plain"); mmp.addBodyPart(body); MimeBodyPart att = new MimeBodyPart(); att.attachFile("c:\\path to file.attachment"); mmp.addBodyPart(att); msg.setContent(mmp); msg.saveChanges(); File resultEmail = File.createTempFile("test", ".eml"); try (FileOutputStream fs = new FileOutputStream(resultEmail)) { msg.writeTo(fs); fs.flush(); fs.getFD().sync(); } System.out.println(resultEmail.getCanonicalPath()); ProcessBuilder pb = new ProcessBuilder(); pb.command("cmd.exe", "/C", "start", "outlook.exe", "/eml", resultEmail.getCanonicalPath()); Process p = pb.start(); try { p.waitFor(); } finally { p.getErrorStream().close(); p.getInputStream().close(); p.getErrorStream().close(); p.destroy(); } } 

电子邮件客户端关闭后,您必须处理清理工作。

您还必须考虑留在文件系统上的电子邮件的安全隐患。