• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Set charset for SMTP

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Setting the charset for an email in my java class does not work. The emails get sent with a different charset other than the one in the code resulting in invalid chars.

When a user enters info on a form, an email is sent to a selected destination. When this is done through a weblogic10 server running on Unix, the result in the headers of the email received is:

Content-Type: text/plain; charset="ISO646-US"



Using the same application build, when i send an email from my localhost through a weblogic10 server running on windows, the result in the headers of the email received is:

Content-Type: text/plain; charset="Cp1252"



I dont understand why this is happenning even though the charset is being set as follows:



The charset ISO646-US results in '?' for all special chars. How can I set the charset to be iso-8859-1 for all content of the email? or is the code not written correctly.

Also would appreciate if anyone can provide any insight into why I get diff charsets when accessing the same java code running on 2 diff OS's.
 
Ranch Hand
Posts: 164
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
In this above code I want to sent mail in html format. How can I set content type
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MimeMessage extends Message which in turn implements Part. That means you get the setContent(Object obj, String type) method. Set the object to be the HTML string, and the type to be "text/html".

Moving to Other JSE/JEE APIs as that is the place for JavaMail.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adrian, if you're still watching this: the charset mentioned in the mail headers has nothing to do with the charset of the individual parts. You didn't mention if the discrepancy you observed was an actual problem or just a curiosity.
 
Adrian Airmil
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Adrian, if you're still watching this: the charset mentioned in the mail headers has nothing to do with the charset of the individual parts. You didn't mention if the discrepancy you observed was an actual problem or just a curiosity.


Paul, this was an actual problem in Production. I have since figured out that the email body received is a sum of 2 parts of data. The first is entered by the user on the web page which is appended to the second which are some properties coded in a java class that does the actual email processing.

So the solution is two fold:
1) set the runtime variable on the server 'java -Dfile.encoding=ISO-8859-1'
2) set the right '-encoding' parameter when building the app to prevent the property value special chars from getting set to 'UFFFF' (unknown char)

So you are right, the charset in the mail headers weren't the issue.
reply
    Bookmark Topic Watch Topic
  • New Topic