如何在java中打开电子邮件客户端并自动附加文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1564147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 14:08:52  来源:igfitidea点击:

How to open an email client and automatically attach file in java

javamailto

提问by Pink Angel

Possible Duplicate:
Java: Start Mail-Client with Attachment?

可能的重复:
Java:使用附件启动邮件客户端?

I need to create a java code that will open an email client (Outlook, outlook express , etc) and automatically attach a file in it. I tried using mailto but it only opens the mail client and do not attach the file. Help please.

我需要创建一个 java 代码,它将打开一个电子邮件客户端(Outlook、outlook express 等)并自动在其中附加一个文件。我尝试使用 mailto,但它只打开邮件客户端,不附加文件。请帮忙。

thanks a lot.

多谢。

采纳答案by Brian de Alwis

JDICprovides some functionality to do this. Although much of JDIC was absorbed into java.awt.Desktopin Java 6, it didn't include the email composition bits. Unfortunately the JDIC binaries disappeared with the transition of java.net to the Kenai platform; I uploaded the most recent versions I could find to the project JIRA.

JDIC提供了一些功能来执行此操作。尽管 JDIC 的大部分内容都被吸收到java.awt.DesktopJava 6 中,但它不包括电子邮件组合位。不幸的是,随着java.net 向 Kenai 平台过渡,JDIC 二进制文件消失了;我上传了我能找到的最新版本到JIRA项目。

JDIC doesn't play well in OSGi, so I recently extracted the relevant MAPI bits into a bundle called jmapi.

JDIC 在 OSGi 中表现不佳,所以我最近将相关的 MAPI 位提取到一个名为jmapi的包中。

回答by ykaganovich

It depends on particular email clients, but &attachmentparameter should work for at least some versions of Outlook.

这取决于特定的电子邮件客户端,但&attachment参数至少应适用于某些版本的 Outlook。

http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx

http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx

回答by delux247

If this is a client application you can take a look at the java.awt.Desktopclass.

如果这是一个客户端应用程序,您可以查看java.awt.Desktop类。

From the javadoc...

从javadoc...

Launches the mail composing window of the user default mail client, filling the message fields specified by a mailto: URI.

A mailto: URI can specify message fields including "to", "cc", "subject", "body", etc. See The mailto URL scheme (RFC 2368) for the mailto: URI specification details.

启动用户默认邮件客户端的邮件撰写窗口,填充由 mailto: URI 指定的消息字段。

mailto: URI 可以指定消息字段,包括“to”、“cc”、“subject”、“body”等。有关 mailto: URI 规范的详细信息,请参阅 mailto URL 方案 (RFC 2368)。

This doesn't allow you to attach a file, but it will open up the user's mail client.

这不允许您附加文件,但它会打开用户的邮件客户端。

This link may be helpful... Using the Desktop API in Java SE 6

此链接可能会有所帮助...使用 Java SE 6 中的桌面 API

回答by Rajiv Makhijani

I answered a nearly identical question here:

我在这里回答了一个几乎相同的问题:

Start Mail-Client with Attachment?

用附件启动邮件客户端?