Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro Java
|
Pro Java Expert level Java questions not about a specific book. Please indicate your version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 21st, 2007, 01:54 AM
Authorized User
 
Join Date: May 2006
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default sending mails with extended character + attachment

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
sending e-mails How To?? saudyonline General .NET 13 November 17th, 2006 01:00 AM
sending mails arabuafef Classic ASP Basics 0 July 18th, 2006 06:29 AM
can VBA script open n mails per attachment each sriramus Access VBA 0 February 20th, 2006 06:24 AM
Sending e-mails using C# lily611 General .NET 3 June 30th, 2004 05:46 AM
Sending mails rajeshnerenki Pro VB 6 4 September 25th, 2003 03:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.