Microsoft KB Archive/191365

= How To Use CDO (1.x) to Get Source Message from Non-Delivery Receipt (NDR) =

Article ID: 191365

Article Last Modified on 7/13/2004

-

APPLIES TO


 * Microsoft Collaboration Data Objects 1.2
 * Microsoft Collaboration Data Objects 1.21

-



This article was previously published under Q191365



SUMMARY
Sometimes it is desirable to programmatically handle receipt of a Non- Delivery Receipt (NDR). To do this, you must trace from the NDR back to the original message that caused it to be generated.

This article explains how to use the Collaboration Data Objects (1.2, 1.21) library to retrieve the original message as well as information about substantial limitations that may apply.



MORE INFORMATION
An NDR can include the original message as an attached embedded message right on the NDR.

The following Visual Basic sample demonstrates how to retrieve an embedded message from an NDR so that it can be programmatically handled as applicable. ' The following Visual Basic code sample assumes a reference to the CDO ' (1.2, 1.21) library (CDO.DLL). ' If you do not have this library please see the following ' article in the Microsoft Knowledge Base: '   ' ARTICLE-ID: Q171440 ' TITLE    : Where to Acquire the CDO (1.x) Libraries '   ' Paste the following code into a new BAS Module in a new Project:

Dim objSess As MAPI.Session Dim objOrigMsg As Message Dim objResendMsg As Message Dim objAttach As Attachment

Sub Main 'Create Session and Logon Set objSess = CreateObject("mapi.session") objSess.Logon

'Go get the NDR. For the sake of simplifying this sample, 'assume the NDR will be the first message in your Inbox. Set objOrigMsg = objSess.Inbox.Messages.GetFirst

'Get a reference to the Attachment. Set objAttach = objOrigMsg.Attachments.Item(1)

'Assign the Source Property of the Attachment to a previously 'defined Message object. Set objResendMsg = objAttach.Source

'At this point the objResendMsg object is a COPY of the original 'message, including all of its properties, recipients, and 'attachments, and is programmatically available for subsequent 'manipulation.

End Sub

' The preceding code sample is not intended to represent a likely implementation, but rather a snippet demonstrating only the elements required to gain access to the original message.

With that said, here's the caveat:

Not all NDR's include this attachment. Any Microsoft product will produce an NDR with this attachment when applicable. However, this is by product design. There is no specification that indicates that an NDR must return this information. In fact, there is no public specification that mandates that an NDR must be returned at all.

The following scenario plays out one possible situation where an NDR might be expected, but may not be returned at all, or may return but without the aforementioned attachment:

 A message is generated and Sent by your Outlook client. The message hits the Spooler. The Spooler hands off the message to the appropriate Transport. The Transport formats the message according to the receiving device, and then facilitates connection to the device (commonly through an Internet Service Provider [ISP]) Here is a possible error:

If the ISP reports that the requested domain is not available, the ISP returns an error to the Transport, and the Transport returns an NDR.

 If step 5 does not apply (the domain is found), the Transport hands the message (through the ISP) to the non-Exchange Server domain server. If the designated recipient does not successfully resolve at the non-MS Exchange server, that server will likely do one of the following:

<ul> Ignore your message and never notify you that it cannot deliver the message.</li> Reply to your message with an NDR, but NOT include a copy of the original message.</li> Reply to your message with an NDR, AND include a copy of the original message.</li></ul>

Which of the three preceding actions takes place is entirely up to how the NDR functionality is implemented by the remote Server application, and is beyond the ability of either Microsoft or your application to control.</li></ol>

Keywords: kbhowto kbmsg kbcode KB191365

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.