'Get the failure reason from a mail in outlook
I am doing some automation on outlook mail box, previously it was lotus notes.So i am looking for equivalent properties in outlook. The lotus notes mail items has a item named FAILUREREASON
which has the details about why the email is failed such as delivery failure reason etc. This item will be available when the mail is a delivery failure email. So when i loop through mails in inbox i can recognize which mail is a delivery failure email in inbox and which is actual required mail to be processed. But in outlook MailItem object i didn't find any option to get it. I searched for any solutuion but not able to find any. We can search subject for words such as 'failure' but it's not good approach. Can anyone know the property that i need to look or any other approach for the same.
Solution 1:[1]
Standard bounce or undeliverable emails are received in Outlook as special items using the "REPORT.IPM.Note.NDR"
message class and are available as a ReportItem
object in the Outlook Object Model. You can also read the mail header information via the PR_TRANSPORT_MESSAGE_HEADERS_W
MAPI property on any kind of email.
One way of retrieving the value is by using PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001F")
Solution 2:[2]
ReportItem
object in the Outlook Object Model (not related to the MailItem
object) exposes NDR information through the ReportItem.Body
property. On the Extended MAPI level (C++ or Delphi only) the properties are stored in the recipient table - you can see the data in OutlookSpy (I am its author) - click IMessage button, go to the GetRecipientTable tab:
For the MailItem
objects, you can access that information using Recipient.PropetyAccessor.GetProperty
method, but ReportItem
object does not expose the Recipients
collection (unlike the MailItem
object). In theory, you can change the MessageClass
property to "IPM.Note"
, remember the value of the EntryID
property, save the NDR, release the original, reopen the item as a regular MailItem
object by calling Namespace.GetItemFromID
, and then read the data from the recipient table. But that means modifying the original NDR (its modification time will change etc.).
If using Redemption is an option (I am its author), its RDOReportItem object (derived from the RDOMail
object) exposes the Recipients
collection. You can reopen Outlook's NDR in Redemption by creating an instance of the RDOSession object and calling RDOSession.GetRDOObjectFromOutlookObject
method. The recipient properties will be accessible using RDORecipient.Fields[]
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitry Streblechenko |
Solution 2 | Dmitry Streblechenko |