qwer11121
qwer11121

Reputation: 168

When sending mail with outlook using C#, How to find out if a recipient will send auto reply?

I am using C# and outlook Interop to send mail, and I want to know if a recipient is in "out of office" status. The status can be found in outlook when i create mail manually, but I don't know how to find it out in C#.

In outlook, it is displayed like this:

autoreply

Does anyone know how to do this? Thanks.

Upvotes: 1

Views: 590

Answers (1)

Shyam sundar shah
Shyam sundar shah

Reputation: 2523

You can use the following code. My assumption, you can check before sending email status adding a new button in the ribbon or during the send email event. I put code during send event

       if(Item is Outlook.MailItem)
        {
            if (Item is Outlook.MailItem)
            {
                Outlook.MailItem mailItem = Item as Outlook.MailItem;
                Outlook.Recipient recipient = mailItem.Recipients[0];
                var result = recipient.FreeBusy(DateTime.Now, 60 * 24);
            }
        }

you need to check result value.

If the optional argument CompleteFormat is omitted or False, then "free" is indicated by the character 0 and all other states by the character 1.

If CompleteFormat is True, then the same length string is returned as defined above, but the characters now correspond to the OlBusyStatus constants.

Indicates a user's availability.

OLBUSYSTATUS ENUMERATION (OUTLOOK)

Name Value Description

olBusy 2 The user is busy. olFree 0 The user is available. olOutOfOffice 3 The user is out of office. olTentative 1 The user has a tentative appointment scheduled. olWorkingElsewhere 4 The user is working in a location away from the office.

Details : https://learn.microsoft.com/en-us/office/vba/api/outlook.olbusystatus

Upvotes: 1

Related Questions