Question

I have found many resources on inspecting the headers in an email to detect whether or not the message was sent using an auto-responder. I'm looking to detect that an auto-responder is configured before any contact is made.

Why I think this is possible: In outlook, if you add a recipient from the address book it will show their auto-responder message above the "To:" line before even clicking send.

Goal: I would like to pass a list of employees to a function and return a binary list of whether or not they are in the office based on auto-responder on/off status.

Some bad psuedo-code (please excuse the mixing of classes and lists, it's just for a simple example).

list = ['Ted Jones', 'Michael Brickman', 'This name', 'That name']

for employee in list:
    if employee.autoresponse != '':
        employee.inoffice = 0

output = [0,1,1,1] #-- So, Ted Jones is out of the office

I'm certainly not stuck on this style of output, just trying to be specific. I need some sort of ordered list or something to tie Name -> In/Out of office

I would like to stay in Python if possible, but am interested to hear other solutions.

Is there anyway to do this? Maybe using win32com or pyad? If a resource for this information exists please let me know... I was unable to find it among the 'check the headers' muck.

Was it helpful?

Solution

You will have to either use Outlook's automation interface, or do the same thing Outlook does (presumably via MAPI or AD), or do the equivalent with some other API.

You can use win32com for the first of the three.

When you add a recipient to the To list in Outlook, it's getting a Recipient object, which has an AutoResponse property, which Outlook will show you.

The easiest (if maybe not the cleanest) way to get a Recipient object through the OOM is to do the exact same thing: create a dummy message, add a recipient, then look at its properties. Items have Recipients objects, which have an Add method that takes an identifier and returns a Recipient (and adds it to the item's recipients, of course).

So, the code should look something like this (untested because I don't have a Windows/Outlook box connected to Exchange here):

session = win32com.client.Dispatch("Mapi.Session")
session.Logon(MY_PROFILE)
outlook = win32com.client.Dispatch("Outlook.Application")

message = outlook.CreateItem(0) # olMailItem
autoresponses = {}
for name in names:
    recipient = message.Recipients.Add(name)
    autoresponses[name] = recipient.AutoResponse

You can of course combine that into a one-liner dict comprehension, but I thought this might be clearer. Also, you probably want to discard the message so Outlook doesn't end up sticking your leftover garbage in Drafts or something, and you probably want some error handling, and you may need to use a separate message for each recipient to make it easier to recover from errors and move on, and so on… But this, together with the MSDN and win32com docs, should be enough to get you going.

Of course this only works if name resolves to a server mailbox; if you give a local-only name or address, or external-only address, you'll just let a local address book entry or a bare email entry, neither of which have an AutoResponse. But that's exactly the same as in Outlook, so presumably it's expected.

Also note that the first time your script does anything that tries to access the Address Book, unless the user has deliberately turned off the default safety features, he will get a popup like "A program is trying to access e-mail addresses you have stored in Outlook. Do you want to allow this?"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top