添加附件邮件到 Outlook

Add attachment mailto Outlook

我想从我的应用程序发送一封电子邮件,代码如下:

public static void mailto(String subject,String path) throws IOException, URISyntaxException {
   String uriStr = String.format("cmd.exe /c start mailto:%s?subject=%s&attachment=%s",
            "test@test.fr",
            urlEncode(subject),
            urlEncode(path));
    Runtime.getRuntime().exec(uriStr);
}

private static final String urlEncode(String str) {
    try {
        return URLEncoder.encode(str, "UTF-8").replace("+", "%20");
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}

window 正常打开,除了 attachment.I 之外一切正常,尝试了很多方法将附件添加到电子邮件中,但是我没有找到解决方案。发送邮件必须通过Outlook界面。

Result of the execution of the code.

感谢您的帮助。

尝试使用 Outlook 客户端可执行文件的固定路径。

public static void mailto(String subject,String path) throws IOException {   
  Runtime.getRuntime().exec("C:\Program Files (x86)\Microsoft Office\Office12\outlook.exe /c ipm.note /m \"test@test.fr&subject="+subject+"\" /a \""+path+"\"");
}