gpt4 book ai didi

java - 使用 Writer 发送带有韩语文本的电子邮件输出垃圾

转载 作者:行者123 更新时间:2023-11-29 23:12:14 25 4
gpt4 key购买 nike

我的应用程序以编程方式发送电子邮件。当正文是英文文本时它有效,但当正文是韩文时它会以垃圾形式出现。例如,发送“테스트”会导致“???”。

这是我用来发送电子邮件的代码:

AuthenticatingSMTPClient client = new AuthenticatingSMTPClient();
try {
client.connect(hostname, port);
client.ehlo("localhost");
if (client.execTLS()) {
client.auth(AuthenticatingSMTPClient.AUTH_METHOD.LOGIN, login, password);

client.setSender(from);

client.addRecipient(to);

Writer writer = client.sendMessageData();

if (writer != null) {
SimpleSMTPHeader header = new SimpleSMTPHeader(from, to, subject);
writer.write(header.toString());
writer.write("테스트);
writer.close();
if (!client.completePendingCommand()) {
throw new Exception("Failure to sendLocation the email " + client.getReply() + client.getReplyString());
}
} else {
throw new Exception("Failure to sendLocation the email " + client.getReply() + client.getReplyString());
}
} else {
throw new Exception("STARTTLS was not accepted " + client.getReply() + client.getReplyString());
}
} catch (Exception e) {
throw e;
} finally {
if (client != null) {
client.logout();
client.disconnect();
}
}

最佳答案

Specify the character encoding当您创建客户端时,例如

AuthenticatingSMTPClient client =
new AuthenticatingSMTPClient(SMTPSClient.DEFAULT_PROTOCOL, "UTF-8");

关于java - 使用 Writer 发送带有韩语文本的电子邮件输出垃圾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55860631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com