How to specify character encoding in JavaMail?

Reply

Join Date: Oct 2008
Posts: 3
Reputation: dwdish is an unknown quantity at this point 
Solved Threads: 0
dwdish dwdish is offline Offline
Newbie Poster

How to specify character encoding in JavaMail?

 
0
  #1
Oct 25th, 2008
Hi, I successfully send email with the following code in English. However, if the message and the subject title are in other characters, everything becomes question marks and the subject title says something like ...ANSI...3F=3F=3F...
How do I set the character encoding to utf-8, for example? Thanks.

I have this in the jsp:

  1. <head>
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Emailing</title>
  5. <link href="/styles.css" rel="stylesheet" type="text/css"/>
  6. </head>

  1. try
  2. {
  3. Properties props = new Properties();
  4. Session sendMailSession;
  5. Transport transport;
  6. sendMailSession = Session.getInstance(props, null);
  7. props.put("mail.smtp.host", SMTP_CLIENT);
  8. Message newMessage = new MimeMessage(sendMailSession);
  9. newMessage.setFrom(new InternetAddress(EMAIL_FROM));
  10. newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(strEmail));
  11. newMessage.setSubject(SUBJECT);
  12. newMessage.setSentDate(new Date());
  13. strMsg = "Dear " + RS.getString("FIRST") + " " + RS.getString("LAST") + ",";
  14. strMsg += "\n\n";
  15. strMsg += [MESSAGE IN CHARACTERS OTHER THAN ASCII];
  16. newMessage.setText(strMsg);
  17. transport = sendMailSession.getTransport("smtp");
  18. transport.send(newMessage);
  19. }
  20. catch(MessagingException m)
  21. {
  22. ...
  23. }
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC