Search code examples
c#outlookvstooutlook-addinoutlook-web-addins

Outlook Add-In: how to automatically reply based on custom logic?


Question

Is it possible with an Outlook add-in to automatically reply only to certain emails/senders, based on custom logic? If so, how?

Examples

Such an add-in might send an automatic reply only to senders not in contacts, or only to senders whose email has been verified by an external service (which the add-in calls to check). This automatic reply might be:

Thanks for your email! I prioritize emails from verified senders. You can verify yourself for free here.

The sender who receives that message could then click the link and verify through the external service. Then, for future emails, the automatic reply would NOT apply to that sender.

Background

Outlook has an automatic reply option in settings, but its functionality is limited to setting a specific message for internal senders and a different one for external senders, plus choosing whether to only use the automatic reply with contacts. There's no built in ability to accomplish what's described in the examples above.

Other Questions and Answers (Possibly Relevant)


Any help would be very much appreciated!


Solution

  • Outlook web add-ins are designed for running for the currently selected item. So, the user should select a particular item in Outlook to activate the add-in. Unlike VSTO where you could handle incoming emails by handling the NewMailEx event of the Application class.

    The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. Use the Entry ID returned in the EntryIDCollection string to call the NameSpace.GetItemFromID method and process the item. This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem, MeetingItem, or SharingItem.

    As soon as you have got an instance of the incoming email you can use the MailItem.Reply method which creates a reply, pre-addressed to the original sender, from the original message.

    Finally, you may find the following articles helpful: