Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Java
  4. How to specify character encoding in JavaMail?

How to specify character encoding in JavaMail?

Scheduled Pinned Locked Moved Java
questiontutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    davilism
    wrote on last edited by
    #1

    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. try { Properties props = new Properties(); Session sendMailSession; Transport transport; sendMailSession = Session.getInstance(props, null); props.put("mail.smtp.host", SMTP_CLIENT); Message newMessage = new MimeMessage(sendMailSession); newMessage.setFrom(new InternetAddress(EMAIL_FROM)); newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(strEmail)); newMessage.setSubject(SUBJECT); newMessage.setSentDate(new Date()); strMsg = "Dear " + RS.getString("FIRST") + " " + RS.getString("LAST") + ","; strMsg += "\n\n"; strMsg += [MESSAGE IN CHARACTERS OTHER THAN ASCII]; newMessage.setText(strMsg); transport = sendMailSession.getTransport("smtp"); transport.send(newMessage); } catch(MessagingException m) { ... }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups