欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

从exchange server 获取out of office 信息

程序员文章站 2022-05-30 16:06:57
...
using System;
using System.Net;
using GetOFFS.sg.com.ncs.webmail;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;


namespace GetOFFS
{

    public class Program
    {
        public static string url = "https://exchangeserveraddress/ews/Exchange.asmx";
        static void Main(string[] args)
        {
            ExchangeServiceBinding esb = new ExchangeServiceBinding();
            esb.Credentials = new NetworkCredential("username", "password", "domain");
            esb.Url = url;
            esb.RequestServerVersionValue = new RequestServerVersion();
            esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2010_SP1;
            GetMessageTrackingReportRequestType gmt = new GetMessageTrackingReportRequestType();
            
            GetMailTipsType gmType = new GetMailTipsType();
            gmType.MailTipsRequested = new MailTipTypes();
            gmType.MailTipsRequested = MailTipTypes.OutOfOfficeMessage;
            gmType.Recipients = new EmailAddressType[1];
            EmailAddressType rcip = new EmailAddressType();
            rcip.EmailAddress = "target@emailaddress";
            gmType.Recipients[0] = rcip;
            EmailAddressType sendAs = new EmailAddressType();
            sendAs.EmailAddress = "target@emailaddress";
            gmType.SendingAs = sendAs;

            GetMailTipsResponseMessageType gmResponse = esb.GetMailTips(gmType);
            if (gmResponse.ResponseClass == ResponseClassType.Success)
            {
                if (gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message != "")
                {
                    //User Out   
                    Console.WriteLine(gmResponse.ResponseMessages[0].MailTips.OutOfOffice.ReplyBody.Message);
                }
                else
                {
                    //user In   
                }

            } 
        }
    }
}
相关标签: net exchange