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!
Your mail is probably send encoded as iso-8859-1, which does not include the codepoint for en-dash. You could try to specify the charset as utf-8 in the setContent call:
This does however not explain the problem with quotes you are seeing, but I guess these are actually two different problems.