【发布时间】:2011-03-11 01:48:21
【问题描述】:
我目前正在使用 JDBC 和 executeQuery 从 MySQL 数据库中获取数据。其中一个字段包含我通过ResultSet.getString("emailBody") 获取的电子邮件内容。
使用以下代码(简化)发送邮件:
Properties props = new Properties();
Session session;
Message message;
props.put("mail.smtp.host", "mysmtpserver");
session = Session.getInstance(props, null);
message = new MimeMessage(session);
message.setFrom(new InternetAddress("myaddress@example.com", "System");
message.setSubject("Automatic notification");
message.setRecipient(RecipientType.BCC,
new InternetAddress("admin@example.com", "Admin Distribution List"));
// email contains the previously fetched value
message.setContent(email, "text/plain");
Transport.send(message);
这适用于所有字符,包括德语变音符号、方括号等。不幸的是,以下字符失败:
– which is displayed as ? on the mail clients
" which becomes \"
' which is sent as \'
我在网上找不到任何有用的东西,请指教。非常感谢!
【问题讨论】: