19

私は Apache Commons 電子メールを使用してクライアントに電子メールを送信していますが、'Semana da Computação' (ポルトガル語 BR) というクライアントがありますが、'Semana da Computaã§ão' になります。コードを変更しようとしましたが、何も機能しません:

public static boolean emailWithImage(String subject, String message, String emailReceiver, String imageURL) {
    HtmlEmail email = new HtmlEmail();
    email.setCharset("UTF-8"); // I change here, but it is not working
    email.setHostName(Constantes.EMAIL_HOST_NAME);
    email.setSmtpPort(587);
    DefaultAuthenticator authenticator =
            new DefaultAuthenticator(Constantes.EMAIL_USER, Constantes.EMAIL_PASSWORD);
    email.setAuthenticator(authenticator);
    email.setTLS(true);

    try {
        email.setFrom(Constantes.EMAIL_USER, Constantes.EMAIL_NAME);
        email.setSubject(subject);
        email.addTo(emailReceiver);

        URL url = new URL(imageURL);
        String cid = email.embed(url, "image");        /* it must be 'cid' the name of the image */

        email.setHtmlMsg("<html><img src=\"cid:" + cid + "\"> <p>" + message + "</p> </html>"); /* set the html message */
        email.setTextMsg(message);                     /* send a alternative text in case when the email reader don't support html */

        email.send();
    } catch (EmailException ex) {
        return false;
    } catch (MalformedURLException ex) {
        return false;
    }

    return true;
}

何か案は?名前が正しく表示されないのはなぜですか?どうすれば修正できますか?

4

3 に答える 3

27

これも機能し、

email.setCharset("utf-8");

または、1.3 を使用している場合は、

email.setCharset(org.apache.commons.mail.EmailConstants.UTF_8);
于 2013-01-23T08:38:22.697 に答える
3

setHtmlMessage(...) を実行する代わりに、

email.addPart("<html>body here</html>", "text/html;charset=UTF-8");

もう 1 つの方法は、文字セットを html に入れてみることです。

email.setHtmlMsg("<html><head><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\"></head>body here</html>");
于 2011-04-25T14:59:09.160 に答える