用附件启动邮件客户端? [英] Start Mail-Client with Attachment?

查看:34
本文介绍了用附件启动邮件客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在寻找一种方法(在 Java 中)来启动默认邮件客户端,其中包含定义的接收者、主题和正文以及预定义的附件.

I'm currently searching for a way (in Java) to start the default mail client with defined receiver, subject and body and with a predefined attachment.

由于 RFC 的限制,java.awt.Desktop.mail-Method 无法处理附件.JDIC 项目已死,而 JMAPI 项目在构建过程中相当模糊.(需要 1.4 Mozilla-Sources)而且我必须自己为 64 位系统构建它.

Due to the limitations of the RFC the java.awt.Desktop.mail-Method is not working with attachments. The JDIC-project is dead and the JMAPI-project is rather obscure in the building process. (Needs 1.4 Mozilla-Sources) And I have to build it for 64 bit systems myself.

有其他选择吗?我已经阅读了这里的文章,但使用 rundl32.dll 和此类解决方案"并不是我想要放入生产代码的东西.

Is there an alternative? I already read the articles here but using the rundl32.dll and such "solutions" aren't something I want to put in production code.

推荐答案

在 Java 中似乎没有任何与操作系统无关的方法来执行此操作,因为并非所有操作系统都提供标准方式来启动默认电子邮件应用程序而不是新电子邮件的基本字段.

There does not appear to be any OS agnostic method of doing this in Java as not all OSes provide a standard way to launch the default e-mail application with more than the basic fields for a new email.

在 Windows 上,可以使用 MAPI 的 JNI 接口,这将提供对在邮件应用程序中打开电子邮件的更多控制.正如您所提到的,JMAPI 就是这样的一个库 - 但是,似乎有许多具有类似目的的名称的库.我发现了一个最近维护的并且看起来相当简单的.它包括一个预先构建的二进制 dll 和一个随附的基于 Java JNI 的库.

On Windows, it is possible to use a JNI interface to MAPI, which will provide more control over opening an email in a mail application. As you mentioned, one such library is JMAPI - however, it appears there are many libraries by such a name with similar purposes. I discovered one that is recently maintained and seems fairly straight-forward. It includes a pre-built binary dll and an accompanying Java JNI-based library.

https://github.com/briandealwis/jmapi

使用此代码,您似乎只需要构造一个消息对象并调用一个方法即可在邮件应用程序中启动它:导入 jmapi.*;...

With this code, it seems you would only need to construct a message object and call a method to launch it in a mail application: import jmapi.*; ...

    if (JMAPI.isMapiSupported()) {
        Message msg = new Message();
        msg.setSubject("test!");
        msg.setBody("Hello world");

        List<String> toAddresses = new LinkedList<String>();
        toAddresses.add("example@example.com");
        msg.setToAddrs(toAddresses);

        List<String> attachPaths = new LinkedList<String>();
        //Must be absolute paths to file
        attachPaths.add("C:UsersDocumentsfile.jpg");
        msg.setAttachments(attachPaths);

        JMAPI.open(msg);
    }

<小时>

另一种可能适用于 Windows 和 Mac(以及可能的其他操作系统)的可能性是生成.eml"或.msg"文件,其中包含您希望包含的已编码为电子邮件一部分的内容和附件.然后可以使用相应电子邮件文件格式的默认处理程序启动该文件.但是,这不能保证打开默认的电子邮件处理程序,文件格式也不能与每个电子邮件客户端兼容.


Another possibility that might work for Windows and Mac (and potentially other OSes) is to generate a ".eml" or ".msg" file with the content and attachments you would like to include already encoded as part of the email. This file could then be launched with the default handler for the respective email file format. However, this is not guaranteed to open the default email handler, nor is the file format going to be compatible with everyone email client.

这篇关于用附件启动邮件客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆