hi i have a problem with extended characters and it only happens when i have an attachment with the mail
my code is as follows
MimeBodyPart bp = new MimeBodyPart();
String content = "Ã Ã Ã Ã Ã Ã
Ã Ã Ã Ã Ã Ã ÃÂ¡ Â¢ Â£ Â¤ Â¥ Â¦ Â§ Â¨ Â© Âª Â« Â Â®";
bp.setContent( content, "text/plain; charset=UTF-8" );
mp.addBodyPart( bp );
//code for adding a attachment is added to the mp using MimeBodyPart
msg.setContent( mp ); // add Multipart
msg.saveChanges(); // generate appropriate headers
ByteArrayOutputStream baos = new ByteArrayOutputStream();
msg.writeTo( baos );
msg is a MimeMessage.
Now this msg is stored in a cache and later retrieved using
String s = "";
java.lang.Object o = msg.getContent();
if ( o instanceof String )
s = (String) o;
else if ( o instanceof Multipart )
Multipart mp = (Multipart) o;
MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart( 0 );
s = (String) bp.getContent();
catch ( Exception e )
now s contains "Ãâ¬ ÃÂ Ãâ ÃÆ Ãâ Ãâ¦ Ãâ Ãâ¡ ÃË Ãâ° ÃÅ Ãâ¹ ÃÅ ÃÂ¡ ÃÂ¢ ÃÂ£ ÃÂ¤ ÃÂ¥ ÃÂ¦ ÃÂ§ ÃÂ¨ ÃÂ© ÃÂª ÃÂ« ÃÂ ÃÂ®" which is wrong.
What I did was i encoded the mail body using UTF-8
MimeUtility.encodeText(content,"UTF-8", null )
now in my application i retrieve the mail and decode it before displaying it to the user. so works fine i.e. the characters are displayed as it should be.
The problem now, is that I require the mails to be view from an external mail client like Microsoft outlook. so here the mail comes but with the UTF-8 encoded data(data encoding is not done).
Previously the mails retrieved from Outlook were totally corrupted. even the attachments, but now the attachments come but the content body is encode.
This has been bugging me for a couple of days now.
could anyone please give a solution. I am looking something that can be altered at the backend(may be with the MIME message itself)
Many Thanks in advance