Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

Get body message exchange server in UTF-8 through transport agent

$
0
0

Hello

I'm trying to save the body message of transport mail item.

Below is my code:

public class MyRoutingAgentFactory : RoutingAgentFactory 
    { 
        public override RoutingAgent CreateAgent(SmtpServer server) 
        { 
            return new MyRoutingAgent(); 
        } 
    }   
    public class MyRoutingAgent : RoutingAgent 
    { 
        public MyRoutingAgent() 
        { 
            base.OnSubmittedMessage += new SubmittedMessageEventHandler(MyRoutingAgent_OnSubmittedMessage); 
        }   
        void MyRoutingAgent_OnSubmittedMessage(SubmittedMessageEventSource source, QueuedMessageEventArgs e)
        {
            string charsetName;
            charsetName = e.MailItem.Message.Body.CharsetName;
            StreamReader reader = new StreamReader(e.MailItem.Message.Body.GetContentReadStream(), Encoding.Unicode, true);
            FileStream fso = new FileStream(@"C:\body.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            StreamWriter writer = new StreamWriter(fso, Encoding.UTF8);
            string temp;
            while ((temp = reader.ReadLine()) != null)
            {
                writer.WriteLine(temp);
            }
            writer.WriteLine(e.MailItem.Message.Body.ToString());
            writer.Flush();
            writer.Close();

            fso.Close();
            reader.Close();

}

}

I sent a test email to get the content of message

Body message that I sent is "Hello, this is test"

But the message I catch in the file not show the content "Hello, this is test". 

Body of message is

搼癩搠物∽瑬≲㰾灳湡猠祴敬∽潣潬㩲杲⡢〸〬㠬⤰㸢浭瑯⼼灳湡㰾牢㰾楤⁶汣獡㵳朢慭汩煟潵整㸢搼癩挠慬獳∽佈湅扚㸢搼癩挠慬獳∽㕨㸢搼癩搠物∽瑬≲㰾楤⁶汣獡㵳朢慭汩煟

So what's problem with my encoding ?

How can I fix it. 


Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>