【问题标题】:Read out of office from exchange server for other users C#为其他用户从交换服务器读取办公室 C#
【发布时间】:2018-06-28 01:24:44
【问题描述】:

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

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

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

我想得到类似的东西:

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

请帮我理解,谢谢。

【问题讨论】:

  • 没有 cmets 的蹩脚投票?在没有反馈的情况下如何改进问题?
  • 我正在研究相同的场景,这是涵盖一系列选项的最详细的帖子。我也不知道为什么有人会否决你,因为你说没有 cmets 所以没有迹象表明出了什么问题。
  • @Myzifer 我能够得到我现在使用的问题的确切解决方案,我只是将其发布为答案。希望对您有所帮助。

标签: c# exchangewebservices exchange-server-2013


【解决方案1】:

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

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;
}

【讨论】:

  • 值得注意的是,我发现“用户”不适用于凭据。在我为用户名指定完整的电子邮件地址之前,我不断收到未经授权的 401,即“user@company.com”。
  • 有人知道凭证必须是什么吗?它适用于普通用户帐户,但不适用于没有指定邮箱的帐户。您提到了“服务帐户”
  • @JensKohl 我们的“服务帐户”只是一个带有邮箱 (AppName@consoto.com) 的专用普通用户帐户
【解决方案2】:

http://blogs.msdn.com/b/devmsg/archive/2014/06/03/ews-how-to-retrieve-the-oof-out-of-facility-settings-message-using-ews-for-an-exchange-user.aspx 这一个作为参数,urlname,我不确定该 url 来自哪里。不过,这似乎是最有前途的,有什么想法吗?

如果您使用托管 API,则 urlname 只是 EWS URL,而不仅仅是使用 service.url 中的值。

http://gsexdev.blogspot.com/2011/11/using-mailtips-in-ews-to-get-oof-out-of.html 我没有引用 ExchangeServiceBinding,即使我使用的是 Microsoft.Exchange.WebServices.Data;

这是从 Exchange Web 服务 WSDL 文件生成的代理代码,请参阅 https://msdn.microsoft.com/en-us/library/office/dd877040(v=exchg.140).aspx (Microsoft.Exchange.WebServices.Data) 是托管 API。

【讨论】:

    【解决方案3】:

    Aaron 提供的解决方案非常适合我。然而,返回子字符串给了我一些问题,因为我们的是一个 html 字符串而不是纯文本,并且它没有正确解析。所以我用以下内容替换了 StreamReader down 部分。这仍然作为字符串返回,但正确地解析为它返回的 html。

            XDocument doc;
            using (Stream responseStream = response.GetResponseStream())
            {
                doc = XDocument.Load(responseStream);
            }
            return doc.Root.Descendants().Where(d => d.Name.LocalName == "Message").Select(d => d.Value).FirstOrDefault();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-09
      • 2017-07-21
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 2012-01-27
      • 2017-07-14
      • 1970-01-01
      相关资源
      最近更新 更多