aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Set charset for SMTP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Set charset for SMTP" Watch "Set charset for SMTP" New topic
Author

Set charset for SMTP

Adrian Airmil
Greenhorn

Joined: Dec 12, 2005
Posts: 24
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.
Vinoth Thirunavukarasu
Ranch Hand

Joined: Dec 18, 2008
Posts: 164

Thank you.
In this above code I want to sent mail in html format. How can I set content type


Java Best Practices
Linux Best Practices
Amortization Calculator

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19544
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

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

Joined: Dec 12, 2005
Posts: 24
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Set charset for SMTP
 
Similar Threads
Mail sending program
use Linux sendmail from Java
cant send mail using JavaMail API
How to send mail using JavaMail API?
Mail API Problem