Meaningless Drivel is fun!*
The moose likes Other JSE/JEE APIs and the fly likes Simple Text based Email : Problem with Russian Characters 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 "Simple Text based Email : Problem with Russian Characters " Watch "Simple Text based Email : Problem with Russian Characters " New topic
Author

Simple Text based Email : Problem with Russian Characters

Balasubramanian Krishnaswamy
Greenhorn

Joined: Jun 26, 2007
Posts: 24
Hi,
My post is regarding sending Email with org.apache.commons.mail.Email.
I am using both Text based and Html based Emails.

I read properties file for Russian characters (converted to \uXXXX format) to build my body of the mail.

The problem is body of the mail displays ??? in Text mails but displays perfectly in HTML mail.

Is there any solution to rectify this. Any special setting to be made in Text based mails.

Thanks in Advance for replying.

Best Regards,
Bala
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9932
    
159

Hello "Bala Kr"
Welcome to JavaRanch

We are glad to have you here. We have a naming policy at JavaRanch. Your displayed name must consist of a first name (or an initial), a space, and a family name (in that order) and not be obviously fictitious. Please take a moment to change it, which you can do right here.


[My Blog] [JavaRanch Journal]
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9932
    
159

Now coming to your question, the SimpleEmail class has a method setCharset where you can specify the charset for the message content. Try using that method.
Balasubramanian Krishnaswamy
Greenhorn

Joined: Jun 26, 2007
Posts: 24
Hi Jai,
Thanks for replying. Please find the below code snippet which I am using.

public void sendTextEmail() throws EmailSendingException {
SimpleEmail email = new SimpleEmail();
setupEmail(email);
email.setCharset("UTF-8");
email.setSubject(subject);
email.setMsg(textBody);
email.send();
}

Also in my properties file I am saving the values as \uXXXX for each key (by using the nativeToascii.exe in ..//jdk/bin folder).

But the strange thing is the subject gets printed correctly but the Mail body goes for a toss (prints ???).

I also tried one more thing, keeping the .properties file content same, I included a line of code before sending the mail.

email.setContent(textBody, "text/plain; charset= UTF-8");

This modification makes the Mail body to display correctly, but the Subject displays as "???".

Then I tried to do something similar to my subject Strng variable.

email.setContent(subject, "text/plain; charset= UTF-8");

But this time it prints some Junk characters in subject (Mail body is ok).

I am totally confused :-( . Please Help me.

Best Regards,
Bala
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9932
    
159

Bala, thanks for changing your display name to conform to our naming policy.
As for the issue that you are seeing, try the following.
Just an example:



See if it works.
Balasubramanian Krishnaswamy
Greenhorn

Joined: Jun 26, 2007
Posts: 24
Hi Jai,
Thanks for providing the code. This is already used in my Java Program. But still I tried your code.

The subject still appears as ??? :-(.

Any other idea to resolve this?

Best Regards,
Bala
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Balasubramanian Krishnaswamy:
Hi Jai,
Thanks for providing the code. This is already used in my Java Program. But still I tried your code.

The subject still appears as ??? :-(.

Any other idea to resolve this?

Best Regards,
Bala

What are you using to view the email? Can this application render Russian characters?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Balasubramanian Krishnaswamy
Greenhorn

Joined: Jun 26, 2007
Posts: 24
I am using Microsoft outlook to view the Email messages triggered from my application.

The problem is my Mail body prints the Russian characters correctly in Text Based mail, but the Mail subject prints "???"

HTML based mail prints both Subject and Body of the mail correctly.

Best Regards,
Bala
Balasubramanian Krishnaswamy
Greenhorn

Joined: Jun 26, 2007
Posts: 24
Hi Jai,
Were you able to find out some solution for the above issue?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9932
    
159

Bala,

Sorry i dont have an answer as to why the subject is not showing up with the right charset. However, i do see similar (if not the same) issues being reported in the Bugzill of Apache Commons Mail Project. I would suggest, you subscribe to their users mailing list and see if any folks from the project can help you out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Simple Text based Email : Problem with Russian Characters
 
Similar Threads
Blank Email Notification
Help required - ContentType "alternate"
Problem viewing German umlauts in certain Outlook 20003
Simple Text based Email : Problem with Russian Characters
strange characters(?) added to the end of my subject text