ID: Q191365
The information in this article applies to:
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 (CDO) library to retrieve the original message as well as information about substantial limitations that may apply.
An NDR can include the original message as an attached embedded message right on the NDR.
The following Visual Basic / Collaboration Data Objects snippet demonstrates how to retrieve an embedded message from an NDR so that it can be programmatically handled as applicable.
Sample Code
-----------
' The following Visual Basic code sample assumes a reference to the CDO
' library:
' CDO.DLL
' If you do not have this library please see the following
' article in the Microsoft KnowledgeBase:
'
' ARTICLE-ID: Q171440
' TITLE : Where to Acquire The Collaboration Data Objects 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:
1. A message is generated and Sent by your Outlook client.
2. The message hits the Spooler.
3. The Spooler hands off the message to the appropriate Transport.
4. The Transport formats the message according to the receiving device, and
then facilitates connection to the device (commonly through an Internet
Service Provider [ISP])
5. 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.
6. 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.
7. If the designated recipient does not successfully resolve at the non-MS
Exchange server, that server will likely do one of the following:
- Ignore your message and never notify you that it cannot deliver the
message.
- Reply to your message with an NDR, but NOT include a copy of the
original message.
- Reply to your message with an NDR, AND include a copy of the
original message.
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.
Additional query words:
Keywords : kbCDO120 kbCDO121 kbMsg kbVBp kbGrpMsg
Version : WINDOWS:1.2,1.21
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 7, 1999