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

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

问题描述

我目前正在搜索一种方式(用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资源)我必须自己构建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 - 但是,似乎有很多这样的名称具有类似目的的库。我发现一个最近被维护,似乎相当直截了当。它包括一个预构建的二进制文件和附带的基于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

使用这段代码,似乎只需要构建一个消息对象并调用一种方法在邮件应用程序中启动它:

import 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:\Users\Documents\file.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天全站免登陆