首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从exchange服务器为其他用户读取C#

从exchange服务器为其他用户读取C#
EN

Stack Overflow用户
提问于 2015-08-24 20:30:19
回答 3查看 2.3K关注 0票数 2

我正在尝试从我的c#程序中读取组织中其他用户的离开办公室状态和消息。我们正在房地内运行Exchange 2013。

这个应用程序是作为一个Active Directory帐户运行的(它有自己的exchange邮箱),我不能使用模拟。

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

我试着弄到这样的东西:

代码语言:javascript
复制
public void checkOOF(string userEmail){
bool isOOF = checkstuff(userEmail);
string message;
if(isOOF)
   message = getOOFMessage(userEmail);
}

请帮我理解,谢谢。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-08-25 04:20:02

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,而不是只使用来自service.url的值,urlname就是EWS。

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

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

票数 1
EN

Stack Overflow用户

发布于 2017-08-30 16:14:07

这就是我最后使用的东西,它起作用了。

代码语言:javascript
复制
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;
}
票数 4
EN

Stack Overflow用户

发布于 2018-06-27 17:24:44

亚伦提供的解决方案对我很有帮助。然而,返回子字符串给我带来了问题,因为我们的字符串是html字符串,而不是纯文本,并且它没有正确地解析。因此,我用以下内容替换了StreamReader下行部分。这仍然以字符串的形式返回,但正确地将其解析为作为返回的html。

代码语言:javascript
复制
        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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32191211

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档