I am quite new to Javamail and its implementations options.
I am able to send email using it with a variety programs but was unable to do so when including chinese characters as part of the email body, in HTML format.
The email I am trying to send is using a template (txt file) that is saved under UTF-8 encoding. I have tried various steps from the internet and wasn't able to get what I expect to receive.
The chinese characters are either displayed as "???" or "親愛的客戶:". But in the subject line, I was able to display the chinese characters properly
Below is some part of my code:
public boolean sendEmailNotice (
String from, String[] to, String subject)
{
try {
InternetAddress[] toList = new InternetAddress[to.length];
toList[0] = new InternetAddress(to[0]);
currentMessage.setFrom(new InternetAddress(from));
currentMessage.setRecipients(Message.RecipientType.TO, toList);
currentMessage.setSubject(subject, "utf-8");
MimeMultipart multipart = new MimeMultipart();
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setText(emailBody, "utf-8", "html");
multipart.addBodyPart(mimeBodyPart);
currentMessage.setContent(multipart);
currentMessage.setSentDate(new Date());
currentMessage.saveChanges();
Transport.send(currentMessage);
} catch (Exception gEx) {
gEx.printStackTrace();
}
return false;
}
=================================================================
// this section is being called separately in the main program before execute the sendEmailNotice to format the emailBody
public String setupEmailContent (Object[] text) {
emailBody = MessageFormat.format(templateStr , text);
return emailBody;
}
Any help will be greatly appreciated.
Thanks.