Send mail with accentued characters using Mail migration API

23 views
Skip to first unread message

Emmanuel dreux

unread,
Jan 15, 2012, 11:13:42 AM1/15/12
to google-app...@googlegroups.com
Hi,

I'm using migrationsample.cs to create a mail in a mailbox using the mail migration APIs.
I'm experiencing problems with accentued characters in the message that become unreadable after migration.

I've managed to handle it encoding the message to base64 before send but the doc says that it's deprecated.
Furthermore, the migrated mail is not using quoted-printable chars like when I receive a mail from another mail application.

Could you post a sample or explain what is the proper way to manage them?
Below is the current solution.

         // RFC 822 email message to migrate.
        private const string rfcTxt =
            "Received: by 10.143.160.15 with HTTP; Mon, 16 Jul 2007 10:12:26 -0700 (PDT)\r\n" +
            "Message-ID: <_messa...@mail.gmail.com>\r\n" +
            "Date: Mon, 16 Jul 2007 10:12:26 -0700\r\n" +
            "From: \"Mr. Serious\" <ser...@adomain.com>\r\n" +
            "To: \"Mr. héhéhéhé\" <test...@apps-provisioning-test.com>\r\n" +
            "Subject: hébé Subject \r\n" +
            "MIME-Version: 1.0\r\n" +
            "Content-Type: text/plain; charset=utf-8\r\n" +
            "Content-Transfer-Encoding: quoted-printable\r\n" +
            "Content-Disposition: inline\r\n" +
            "Delivered-To: test...@apps-provisioning-test.com\r\n" +
            "\r\n" +
            "ééé\r\n" +
            "\r\n";

        static public string EncodeTo64(string toEncode)
        {
            Encoding enc = new UTF8Encoding(true, true);
            byte[] bytes = enc.GetBytes(rfcTxt);

            string returnValue = System.Convert.ToBase64String(bytes);
            return returnValue;
        }

        private static string GenerateRandomRfcText()
        {
            [...]
            return EncodeTo64(result);
        }

       private static MailItemEntry SetupMailItemEntry(string batchId)
       {
            [...]
            entry.Rfc822Msg = new Rfc822MsgElement(GenerateRandomRfcText());
            entry.Rfc822Msg.MessageEncoding = Rfc822MsgElement.EncodingMethod.BASE64;
       }

Gunjan Sharma

unread,
Jan 17, 2012, 12:05:23 AM1/17/12
to google-app...@googlegroups.com
Hello Emmanuel

I tried to migrate your message using Python Client library and I was able to migrate it as it is.
The function here also uses Base64 encoding. I am currently looking to find out the .NET equivalent for it.
I will update the thread as soon as possible. For the time, here is the Python code that I used.

service = service.MigrationService(domain=domain, source='sample')
service.SetOAuthInputParameters(
        gdata.auth.OAuthSignatureMethod.HMAC_SHA1,
        CONSUMER_KEY, CONSUMER_SECRET)
        
request_token = service.FetchOAuthRequestToken()
service.SetOAuthToken(request_token)
auth_url = service.GenerateOAuthAuthorizationURL()
print auth_url
raw_input('Manually go to the above URL and authenticate.'
              'Press enter after authorization.')
service.UpgradeToOAuthAccessToken()
mail_item_properties = ['IS_INBOX', 'IS_STARRED']
mail_labels = ['Imported']
message = ("Received: by 10.143.160.15 with HTTP; Mon, 16 Jul 2007 10:12:26 -0700 (PDT)\r\n"
            "Message-ID: <_mes...@mail.gmail.com>\r\n"
            "Date: Mon, 16 Jul 2007 10:12:26 -0700\r\n"
            "From: \"Mr. Serious\" <se...@adomain.com>\r\n"
            "To: \"Mr. héhéhéhé\" <tes...@apps-provisioning-test.com>\r\n"
            "Subject: hébé Subject \r\n"
            "MIME-Version: 1.0\r\n"
            "Content-Type: text/plain; charset=utf-8\r\n"
            "Content-Transfer-Encoding: quoted-printable\r\n"
            "Content-Disposition: inline\r\n"
            "Delivered-To: test...@apps-provisioning-test.com\r\n"
            "\r\n"
            "ééé\r\n"
            "\r\n")

print message

service.ImportMail(user_name='admin',
                             mail_message=message,
                             mail_item_properties=mail_item_properties,
                             mail_labels=mail_labels)

Gunjan Sharma

unread,
Jan 17, 2012, 6:48:20 AM1/17/12
to google-app...@googlegroups.com
Hello Emmanuel

Your sample works in .NET. I used your functions and I was able to migrate mails with accented chars.
I am attaching the cs file that I used for your reference. Please try again and let us know if you face any problems.

Thanks
Gunjan Sharma
migrationsample.cs

Emmanuel dreux

unread,
Jan 20, 2012, 11:17:35 AM1/20/12
to google-app...@googlegroups.com
Hi,
yes it works, I'm now using it in my project.
I just thought that there would be a better way to do it as the doc said that Base64 was deprecated.

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages