none
Please help with MS Exchange Transport Agent code to replace email Subject line. RRS feed

  • Question

  • I have created a custom Exchange Transport Agent. The code is below. It is supposed to replace the message Subject line for a particula recepient. I have installed it on Exchange 2010 server but it doesn't do anything. Thank you.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Exchange.Data.Transport.Smtp;
    using Microsoft.Exchange.Data.Transport;
    using Microsoft.Exchange.Data.Transport.Routing;
    using System.Diagnostics;
    using System.Globalization;
    
    namespace MyReportShareAgent
    {
    
        public sealed class MyAgentFactory : RoutingAgentFactory
        {
            public override RoutingAgent CreateAgent(SmtpServer server)
            {
                RoutingAgent myAgent = new MyRoutingAgent();
                return myAgent;
            }
        }
    
        public class MyRoutingAgent : RoutingAgent
        {
    
    
    
    
            public MyRoutingAgent()
            {
                //subscribe to different events 
                base.OnSubmittedMessage += new SubmittedMessageEventHandler(SRoutingAgent_OnSubmittedMessage);
            }
    
    
            void SRoutingAgent_OnSubmittedMessage(SubmittedMessageEventSource source, QueuedMessageEventArgs e)
            {
    
    
    
    
                if (e.MailItem.Message.To.Equals("report@company.com"))
                {
                    try
                    {
                        e.MailItem.Message.Subject = "PP" + GetWeekNumber(DateTime.Now);
    
                    }
                    catch (Exception except)
                    {
    
                    }
                }
    
                
            }
    
    
            public static String GetWeekNumber(DateTime dtPassed)
            {
                CultureInfo ciCurr = CultureInfo.CurrentCulture;
                int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Thursday);
                String weekString = ((weekNum + 1) / 2).ToString();
                return weekString;
            }
    
        }
    }


    sean zhang signature

    Friday, April 13, 2012 8:27 PM

All replies