Profil von hanbinActionXPFotosBlogListen Extras Hilfe

Blog


    29 November

    [Summary No.2] Exchange 2007 Transport Agent coding

    NOTE: We are using C#. In this sample, the Outbound agent responds to the OnRoutedMessage event, and the Inbound agent responds to the OnEndOfHeaders and OnRcptCommand events.

     

    Function of the condition A.a: Identify whether the mail is from Anonymous connection.

    In this stage, the whole message has already been submitted. So we can get the answer from the MIME message header.

     

            /// <summary>

            /// Returns whether this message was submitted on an anonymous SMTP connection

            /// </summary>

            /// <param name="headers">The message headers</param>

            /// <returns>true if the message was anonymously submitted

            /// Exception could be thrown if the message MIME header was corrupt

            ///</returns>

            private static bool IsAnonymous(HeaderList headers)

            {

                Header authHeader = headers.FindFirst("X-MS-Exchange-Organization-AuthAs");

                    return (authHeader == null ||

                    string.IsNullOrEmpty(authHeader.Value) ||

                    authHeader.Value.Equals(

                        "Anonymous",

                        StringComparison.OrdinalIgnoreCase));          

            }

     

     

    28 November

    [Summary No.1] Exchange 2007 Transport Agent coding

    How to determine the mail flow direction on HUB/Edge? Outbound or Inbound.

     

    First of all, we need to make the agreement on the definition of Outbound and Inbound e-mail.

     

    A. Outbound mail must meet the following conditions at the same time:

    A.a. NOT submitted by anonymous connection (Can be relay, but do not like free relay, sorry)

    A.b. The sender's SMTP domain is in the domain list in Accepted Domains (can be from authoritative or partner's domain).

    A.c. At least one of the recipients' SMTP domain is NOT in the authoritative domain list in Accepted Domains. (If all recipients are hosted by this org, it is an internal mail.)

     

    B. Inbound mail must meet the following conditions at the same time:

    B.a. exception of condition a and b of above.

    B.b. At least one of the recipients' SMTP domain is in the authoritative domain list in Accepted Domains. The scope is the org hosted by the exchange server and does not include relay or partner domains.

     

    Now the logistic is clear, let's go ahead with the code tomorrow.

     
     
     
     
    27 November

    新窝

    想了解本人最新八卦的,请关注右边的条有什么变化。。。
     
    好吧,我终于不得不承认Eric Dai同学真的好八卦,这不,两个沙发都被他抢了。。。
     
    23 November

    Nice internal tracers in Exchange 2007

    Just finished the POC work of an Exchange 2007 development project. I wrote two Exchange Transport Agents which hooks on OnEndOfHeaders and OnRcptCommand of SmtpReceiveAgent and OnRoutedMessage of RouteAgent. 

     

    The Exchange 2007 Transport Agent programming is brand new. The class, method, property, functions and etc are all new! While the most painful thing is that we have very few sample codes for reference. Few people on Internet or tech groups have experience on writing such complex transport agents. 

     

    One interesting thing is that the Exchange 2007 actually provides a set of diagnostics tracers interface for its internal agents. In Exchange 2003 age, it is hard to use them in our own application. But Exchange 2007 actually exposes them freely for the DEV peoples. Meanwhile, the tracers are very powerful and have the following advantages:

    1.    Easy to invoke and easy to use.

    2.    It is using ETL tracing. The performance impact is small than normal tracers like log files or event log or database.

    3.    We can use the tool “Mail Flow Troubleshooter” in Exchange Management console to catch, view, search and export the trace (can be XML/CSV/HTML format).

     

    Is it cool?

     

    Now let’s talk how to this works:

     

    In this example (C#), we will use the Commontracer of the Exchange server’s internal diagnostic tracers.

     

    // First of all, you need to add reference library by adding the following DLL file.

    Exchange Server\Bin\Microsoft.Exchange.Diagnostics.dll

    //Now you load the tracer functions.

    //To output Error type trace

    ExTraceGlobals.CommonTracer.TraceError()

     

    //To output Debug type trace

    ExTraceGlobals.CommonTracer.TraceDebug(int lid, long id, string, params)

    //Others like

    ExTraceGlobals.CommonTracer.TraceWarning()

    ExTraceGlobals.CommonTracer.TraceInformation()

    ExTraceGlobals.CommonTracer.TraceFunction()

    ExTraceGlobals.CommonTracer.TracePerformance()

    ExTraceGlobals.CommonTracer.Pfd()

     

    //Sample code:

    ExTraceGlobals.CommonTracer.TraceDebug(this.GetHashCode(), "My name is {0} {1}. I come from {2}", myfirstname, mysecondname, mycountry);

     

     

    How to trace the agent

    ---------------------------------

    The trace is using the Microsoft Exchange Diagnostics tracer and provides very detail output for every step in the mail flow. We can enable, capture, view, search, and export the trace easily in Microsoft Exchange Management Console.

     

    NOTE:

    1. Trace could affect the server performance.

    2. ETL trace file could be big on a busy server. Please make sure you have enough disk space.

     

    To enable and catch trace:

    1. Open Exchange Management Console, go to Toolbox, open Mailflow Troubleshooter

    2. Click “Select a task” in the left window, click “Trace Control” in the right window, click OK.

    3. Change the ETL filename and path, click “set manual trace tag”

    4. Under “Trace Type”, select one or several from Pfd/Fatal/Error/Warning/Info/Debug/Function/Performance.

    5. Under “Components to trace”, select Common.

    6. Under “Trace tag”, fill the checkbox Common. Leave the other checkboxes empty.

    7. Click “Start Tracing”.

    8. After running a while or reproducing some issue, you can click “Stop tracing now” to stop trace.

     

     

    To view trace:

     In the left window, click “select a result file to view”, select one report from the list, and then click “View result”.

     

    To search words in the trace:

    After opening one trace report, click “Find” to find strings.

     

    To export trace:

    After opening one trace report, click Export report, you can then export the report into a file with HTML/XML/CSV format.

     

     

     

     

    12 November

    发芽

    在新加坡的“热土”上,我的心和我的葱都在慢慢发芽。
     
    某日,想起当初和老爸在一起种菜的日子,兴致大发。待到月黑风高之夜,下去小区里“请”了些土上来,顺手装进从旧货市场淘来的那只大玻璃盆中,栽上几根葱根,最后浇上一些稀释的牛奶。嘿,没几天还真的发芽了~~
     
    无疑,把晨晨和牛奶相比也再恰当不过了。雪白的皮肤,雪白的心灵,以及那丝般的温柔。
     
    是的,我,就是那根葱。。。
     
    只有晨晨,能让我忘记过去。
    只有晨晨,能使暴躁的我平静下来。
    只有晨晨,能让希望慢慢在我心中发芽,长大。
     
     
    06 November

    无聊下,写个PowerShell小程序换换脑子

    可以加到MOM或者NetIQ里面,监控某些归档邮箱的使用情况(数量,尺寸),并且自动将报警写入应用日志中。

     

    Sample:

    #===============

     

    #some global variables

    $danger_itemcount = 1000   #put your threshold value here

    $danger_itemsize = 10000   #put your threshold value here

    $MBinfo = get-mailboxstatistics -identity journalmbx1  #you may want to make the code as a function and put $args[0] here

     

    #check mailbox item count

    If ($MBinfo.itemcount -gt $danger_itemcount)

    {

    # create a warning event ID 5555

    $evt=new-object System.Diagnostics.EventLog("Application")

    $evt.Source="CheckingMB"

    $infoevent=[System.Diagnostics.EventLogEntryType]::Warning

    $evt.WriteEntry("The archive mailbox has items over "+$danger_itemcount,$infoevent,5555)

     

    }

     

    #check mailbox total item size

    If ($MBinfo.totalitemsize -gt $danger_itemsize)

    {

    # create a warning event ID 6666

    $evt2=new-object System.Diagnostics.EventLog("Application")

    $evt2.Source="CheckingMB"

    $infoevent=[System.Diagnostics.EventLogEntryType]::Warning

    $evt.WriteEntry("The archive mailbox has total size over "+$danger_itemsize,$infoevent,6666)

    }

     

    #===============