简体   繁体   中英

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

This is what iam currently doing:

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();
    }
}

It works perfect for .txt and .doc(without text formation). But still its not quite satisfying since i cant send formatted text to the standart desktop email cleint, because im forced to generate an url. Does anybody know a way to parse formatted text to the email client via mailto or anything else?

No. This is not a limitation of java, but of the mailto url format (check RFC2368 ). It would be the same in a web browser for instance.

See MailTo with HTML body

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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