1
votes

The code below can fail due to a lot of causes, e.g., invalid recipients list or nonexistent recipients. For these problems the sender of the mail will get non-delivered report to his inbox.

What I want to achieve is, if the sent email fails because of improper recipient id, then I should intercept the Exception at Catch branch.

try
{
    Outlook.MailItem mail = OutLookInstance.CreateItem(Outlook.OlItemType.olMailItem);
    mail.Subject = "Send to TAM";
    mail.Recipients.Add("[email protected]");
    mail.Body = "Business Alert mail";
    mail.Display(false);
    mail.OriginatorDeliveryReportRequested = true;
    mail.Send();
}
catch(Exception ex)
{
}

The above code is supposed to do that, but it does not throw any exception if the delivery fails.

How to achieve this using Outlook, please let me know?

1
You can't. An NDR is essentialy a second email that is sent in response to your first email. In order to receive it the original email must be sent successfully. In short all you can know when sending an email is did the mail server accept the email, you can't know whether it was delivered correctly. This is a limitation of email generally.Ben Robinson
Thanks Ben, is there any other alternative so that we can guarantee that email is sent recipient successfully.sanjayts
No there is no way to ensure that an email is successfully received.Ben Robinson

1 Answers

1
votes

You need to use the Resolve or ResolveAll methods of the Recipient or Recipients class to resolve a Recipient object against the Address Book.

You can find a sample code in C# and VB.NET in the How To: Create and send an Outlook message programmatically article.