【发布时间】:2019-04-26 03:59:54
【问题描述】:
我的应用程序以编程方式发送电子邮件。当正文是英文文本时它可以工作,但当正文是韩文时,它会作为垃圾出现。例如发送 '테스트' 结果为 '???'。
这是我用来发送电子邮件的代码:
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();
}
}
【问题讨论】: