gpt4 book ai didi

c# - 从 exchange 服务器读取外出办公室供其他用户使用 C#

转载 作者:行者123 更新时间:2023-11-30 20:22:20 26 4
gpt4 key购买 nike

我正在尝试从我的 C# 程序中读取组织中其他用户的外出状态和消息。我们在本地运行 Exchange 2013。

此应用作为 Active Directory 帐户运行(具有自己的交换邮箱),我无法使用模拟。

我花了一些时间尝试解决类似问题,例如:

我想得到类似的东西:

public void checkOOF(string userEmail){
bool isOOF = checkstuff(userEmail);
string message;
if(isOOF)
message = getOOFMessage(userEmail);
}

请帮我理解一下,谢谢。

最佳答案

这就是我最终使用的并且有效。

public static string getOOM(string emailToCheck) //needs to be full email of user.
{
string EWSurl = String.Format("https://{0}/EWS/Exchange.asmx", ExchangePath);
WebRequest webRequest = WebRequest.Create(EWSurl);
HttpWebRequest httpwebRequest = (HttpWebRequest)webRequest;
httpwebRequest.Method = "POST";
httpwebRequest.ContentType = "text/xml; charset=utf-8";
httpwebRequest.ProtocolVersion = HttpVersion.Version11;
httpwebRequest.Credentials = new NetworkCredential("user", "password", "domain");//service Account
httpwebRequest.Timeout = 60000;
Stream requestStream = httpwebRequest.GetRequestStream();
StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);

StringBuilder getMailTipsSoapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
getMailTipsSoapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
getMailTipsSoapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ");
getMailTipsSoapRequest.Append("xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\"><soap:Header>");
getMailTipsSoapRequest.Append(" <t:RequestServerVersion Version=\"Exchange2010\"/></soap:Header><soap:Body>");
getMailTipsSoapRequest.Append("<GetMailTips xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\">");
getMailTipsSoapRequest.Append("<SendingAs>");
getMailTipsSoapRequest.Append("<t:EmailAddress>accessingemail@domain.com</t:EmailAddress>");
getMailTipsSoapRequest.Append("<t:RoutingType>SMTP</t:RoutingType></SendingAs>");
getMailTipsSoapRequest.Append("<Recipients><t:Mailbox>");
getMailTipsSoapRequest.Append("<t:EmailAddress>" + emailToCheck + "</t:EmailAddress>");
getMailTipsSoapRequest.Append("<t:RoutingType>SMTP</t:RoutingType></t:Mailbox></Recipients>");
getMailTipsSoapRequest.Append(" <MailTipsRequested>OutOfOfficeMessage</MailTipsRequested></GetMailTips>");
getMailTipsSoapRequest.Append("</soap:Body></soap:Envelope>");

streamWriter.Write(getMailTipsSoapRequest.ToString());
streamWriter.Close();
HttpWebResponse webResponse = (HttpWebResponse)httpwebRequest.GetResponse();

StreamReader streamreader = new StreamReader(webResponse.GetResponseStream());
string response = streamreader.ReadToEnd();
if (response.Contains("<t:Message/>"))
return null;
int messageIndex = response.IndexOf("<t:Message>");
response = response.Substring(messageIndex, response.IndexOf("</t:Message>") - messageIndex);
return response;
}

关于c# - 从 exchange 服务器读取外出办公室供其他用户使用 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32191211/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com