HOWTO: Generate a Value for PR_MTS_ID

ID: Q183920

The information in this article applies to:

SUMMARY

Occasionally, Microsoft Exchange Server 4.0 rejects some inbound gateway mail messages because the foreign gateway relied upon the Exchange Server to supply a value for PR_MTS_ID. In particular, messages that have been addressed to recipients homed on an Exchange server in the same site, other than the gateway server, will be rejected.

The cause of this behavior is the value for PR_MTS_ID supplied by Exchange Server. At times, that value may be rejected as invalid, resulting in NonDelivery of inbound foreign mail messages.

To avoid this issue, gateway programs should generate a value for PR_MTS_ID and place it on the Message Transfer Envelope of the inbound message. The code sample in the MORE INFORMATION section demonstrates the correct method to accomplish this task.

MORE INFORMATION

To build this sample with Developer Studio, create a new "Win32 Console Application" project and create a new "CPP Source" file called Main.

1. Make sure to include these files:

      #include <windows.h>
      #include <string.h>
      #include <stdio.h>
      #include <winbase.h>

2. Copy the following code entirely and past it into the file window.

      /* Generate an MTS-ID value for tracking inbound messages,
         and to correctly route Non-Delivery Reports. */ 

      #define MAX_LENGTH_MTS_ID 255

      void main( )
      {

      /* A pocket for the generated MTS_ID value. */ 
      LPSTR   lpszMTSID;

      /* Character buffer for munching on the X400 ID. */ 
      CHAR    buf1[MAX_LENGTH_MTS_ID];

      /* An X400 ID from any recipient. */ 
        LPSTR   lpszX400Adr = NULL;

      /* String pointer. */ 
        LPSTR   p = NULL;

      /* The name of the computer running this code. */ 
        CHAR    szComputerName[MAX_COMPUTERNAME_LENGTH+1];

      /* Defined in Winbase.h */ 
        DWORD   dwCompNameBufferSize = MAX_COMPUTERNAME_LENGTH;

      /* Obtain the system time. Assists to make this value unique. */ 
        SYSTEMTIME  sysTime;
        GetSystemTime( &sysTime );

      /* Supply a valid X400 address to use in the MTS_ID value.
         For example, the gateway administrator's X400 proxy. */ 
        lpszX400Adr = "c=US;a= ;p=FooSite;s=TomBoy;";

      /* Set the first character in the buffer to NULL */ 
        buf1[0] = '\0';

      /* Find the first semicolon in the X400 Address.
         The semicolon is the element separator in the address type. */ 
        p = strtok(lpszX400Adr, ";")

      /* As long as there is an element at p, check to see if the
         character is 'c' or 'a' or 'p', AND the next character is an
         '='. If so, we have an element of the X400 address. */ 
        while (p)
        {
            if (('c'== *p || 'a'== *p || 'p' == *p) && '=' == *(p+1))
            {
              /* Put it in the buffer, and add a semicolon. */ 
              strcat(buf1, p);
              strcat(buf1, ";");
            }
            /* Find the next element in the X400 address. */ 
            p = strtok(NULL, ";");
        }

        /* The next component of the PR_MTS_ID value is the name of the
           computer running this program. For now, assume that this call
           always works. For more information on GetComputerName, look
           under "Setup and Systems Management Services" in the
           Platform SDK. */ 

        GetComputerName(szComputerName, &dwCompNameBufferSize);

        /* GetComputerName does not null-terminate the returned string,
           so we do it. */ 
        szComputerName[MAX_COMPUTERNAME_LENGTH] = '\0';

        /* Copy the whole mess into a string. */ 
        sprintf(lpszMTSID,
          "%sl=%s%02d%02d%02d%02d%02d%02d%04d", buf1, szComputerName,
          sysTime.wYear % 100, sysTime.wMonth, sysTime.wDay, sysTime.wHour,
          sysTime.wMinute, sysTime.wSecond, sysTime.wMilliseconds);

        /* Tell the world. */ 
        printf("The MTS_ID value is %s\n", lpszMTSID);
        return;
      }

3. Set a breakpoint at the return statement.

4. Compile and run the program.

5. Switch to the console window where the MTS-ID generated by this program

   should appear.

Keywords          : XFOR 
Version           : WINDOWS:4.0
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: April 16, 1998