Results 1 to 8 of 8
  1. #1
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default javamail > subject encoding issue?

    Hi All,

    I am trying to have the subject of my email in international character. However, i couldn't find a way to set encoding for it since the msg.setSubject(String) take only a string as its param. The body is fine since we can do it through setDataHandler(...) method with encoding option.

    i don't know if you have sample code or ideas to do it?

    thank you for your help,

    -Hoang Long

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    304
    Rep Power
    6

    Default

    If you look inside the MimeMessage API there is a setSubject(String, String) method that allows you to specify the character set.

    MimeMessage (JavaMail API documentation)

    Hope that helps.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Keep in mind, in general, you cannot type arbitrary Unicode characters into String literals. Use Unicode escapes. Actually sometime it's bit of mess-up type lots of Unicode escapes. So that if you want use a resource file, keep all the content on it and read the relevant if necessary, so that you've control over the encoding.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    I think MimeMessage API has a description about that too, and there is a method to write them to a text file too.

  5. #5
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    thank you. i didn't notice this. i was using Message class and instantiate as MimeMessage and it made me trouble finding where another setSubject method with encoding support is.

    thanks.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  7. #7
    litpuvn is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    it's done. thank you very much.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

Similar Threads

  1. Replies: 3
    Last Post: 06-03-2010, 09:04 PM
  2. Encoding Problem
    By GJ! in forum Advanced Java
    Replies: 6
    Last Post: 01-12-2010, 08:09 PM
  3. encoding issue in jsp
    By sams11 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-25-2008, 07:55 AM
  4. How to specify character encoding in JavaMail?
    By jfcup in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 10-24-2008, 07:55 PM
  5. Some help with encoding...
    By nm123 in forum Networking
    Replies: 0
    Last Post: 04-15-2008, 12:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •