I'm currently fetching data from a MySQL database using JDBC and executeQuery
. One of the fields contains the email content, which I fetch via ResultSet.getString("emailBody")
.
The mail is sent using the following code (simplified):
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);
This works fine for all characters, including german umlaute, brackets, etc. Unfortunately the following characters fail:
– which is displayed as ? on the mail clients
" which becomes \"
' which is sent as \'
I couldn't find anything useful on the web, please advise. Many thanks!