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
Code:
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
Code:
String s = "";
java.lang.Object o = msg.getContent();
if ( o instanceof String )
s = (String) o;
else if ( o instanceof Multipart )
{
try
{
Multipart mp = (Multipart) o;
MimeBodyPart bp = (MimeBodyPart) mp.getBodyPart( 0 );
s = (String) bp.getContent();
}
catch ( Exception e )
{
cLog.error(e.getMessage(),e);
}
}
now s contains "Ã⬠àÃâ ÃÆ Ãâ Ã⦠Ãâ Ãâ¡ ÃË Ãâ° ÃÅ Ã⹠Êá â ã ä ÃÂ¥ æ ç è é ê ë àî" which is wrong.
What I did was i encoded the mail body using UTF-8
Code:
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