繁体   English   中英

是否可以将Java mail(mailto)函数与.docx或格式化的.doc文件一起使用?

[英]Is it possible to use the java mail(mailto) function with .docx or formatted .doc files?

这是iam当前正在做的事情:

private void openEmailButtonMouseClicked(MouseEvent e) {

    String mailto = getClientConfigValue("email", "mailto");
    String ccto = getClientConfigValue("email", "ccto");
    String subject = getClientConfigValue("email", "subject");
    String body = getClientConfigValue("email", "body");
    String currClient = getCurrClient();
    String bodyPath = getSpecificClientConfigPath(currClient) + body;
    String text = "";

    try {
        BufferedReader br = new BufferedReader(new FileReader(bodyPath));
        try {
            StringBuilder sb = new StringBuilder();
            String line = br.readLine();

            while (line != null) {
                sb.append(line);
                sb.append(System.lineSeparator());
                line = br.readLine();
            }
            text = sb.toString();
            while (text.contains(" ")) {
                text = text.replace(" ", "%20");
            }
            text = text.replaceAll("(\r\n|\r|\n|\n\r)", "%0A");
        }
        finally {
            br.close();
        }
    }
    catch (Exception e1) {
        e1.printStackTrace();
    }

    try {
        Desktop.getDesktop().mail(new URI("mailto:" + mailto + "?subject=" + subject + "&cc=" + ccto + "&body=" + text));

    }
    catch (Exception e1) {
        e1.printStackTrace();
    }
}

它非常适合.txt和.doc(无文本格式)。 但是仍然不能令人满意,因为我无法将格式化的文本发送到标准的台式机电子邮件处理系统,因为我被迫生成了一个URL。 有谁知道一种通过mailto或其他方式将格式化文本解析为电子邮件客户端的方法吗?

否。这不是Java的限制,而是mailto url格式(请参阅RFC2368 )。 例如,在Web浏览器中将是相同的。

请参阅带有HTML正文的MailTo

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM