none
Sharepont2010 如何单点登录 OWA RRS feed

  • 问题

  • 有一个webpart显示 owa中未读邮件《 目前需要点击 某条未读邮件 ,直接向owa中打开一样,定位到该邮件!

    目前问题:

    1.点击邮件时,连接到owa需要用户输入用户名和密码登录, sharepoint和owa都是基于AD,想的是,sharepoint已经验证 了,owa就不输入密码了.

    目前使用的是记住密码的。

    2.https://mail.server.com/owa/?ae=Item&a=Open&t=IPM.Note&id=RgAAAABh3SkfFRJjTZvjszfyM4LlBwB4XADDrEFhSI1I0ylHUJ6jAAAAeFnRAAB4XADDrEFhSI1I0ylHUJ6jAAAHaZQWAAAA

    该ID不知道如何生成? 关于这个问题另参考 :http://social.technet.microsoft.com/Forums/zh-CN/exchangesvrdevelopment/thread/17cdb574-cd96-49c4-9f7b-0e012842954f

    i create a post in the notes folder of a specified mailbox. I use the EWS 2007 to do this. Then I would like to return the URL to open this post in a web-browser. However, it should open the view in which I can write an reply. The URL looks in general thus:

    https://SERVER_ADRESS/owa/?ae=PreFormAction&a=PostReply&t=IPM.Post&id=RgAAAADMJNzMj%2brsS4PO%2fGghaEMzBwC%2bRmxcHl5lT6Y3dNT3xAfHAA9cUnVsAAC%2bRmxcHl5lT6Y3dNT3xAfHAFr%2fAYscAAAW&fId=LgAAAADMJNzMj%2brsS4PO%2fGghaEMzAQC%2bRmxcHl5lT6Y3dNT3xAfHAA9cUnVsAAAB

    As is to be seen, contain this address two IDs. The first is the OWAId (RgAAA...). I can generate this with the following code:

    ConvertIdType IdConverter = new ConvertIdType(); 
    IdConverter.DestinationFormat = IdFormatType.OwaId; 
     
    IdConverter.SourceIds = new AlternateIdType[1]; 
     
    AlternateIdType IdToConvert = new AlternateIdType(); 
    IdToConvert.Format = IdFormatType.EwsId; 
    IdToConvert.Mailbox = sender
    IdToConvert.Id = message.MessageType.ItemId.Id; 
    IdConverter.SourceIds[0] = IdToConvert; 
                     
    ConvertIdResponseType cIDResponse = svc.ConvertId(IdConverter); 

    But how can I generate the seccond ID (LgAAA...)?

    Greetz
    Denis

    但是此方法已测试, OWAId 获取不对, 

    谢谢.


    Anything is Possible!

    2012年5月24日 3:18

答案

  • Hi harvey,

    下面的方法不知道你有没有尝试过。

    private int GetUnReadMailCount()
            {
                string url = "http://10.10.10.254/exchange/"; //指定Exchange服务器地址 
                System.Net.HttpWebRequest Request;
                System.Net.WebResponse Response;
                System.Net.CredentialCache MyCredentialCache;
                string strUserName = UserName; //指定登录的用户名
                string strRootURI = url + strUserName; //得到要访问邮箱的WebDAV地址
                string strPassword = PassWord; //指定该用户的密码
                string strDomain = "unique.com"; //指定域名
                string strQuery = "";
                byte[] bytes = null;
                System.IO.Stream RequestStream = null;
                System.IO.Stream ResponseStream = null;
                XmlDocument ResponseXmlDoc = null;
                XmlNodeList HrefNodes = null;
                XmlNodeList SizeNodes = null;
                int count = 0;
                try
                {
                    // 用SQL查询WebDAV返回结果中的unreadcount节点.
                    strQuery = "<?xml version=/"1.0/"?><D:searchrequest xmlns:D = /"DAV:/" >"
                         + "<D:sql>SELECT /"DAV:displayname/",/"urn:schemas:httpmail:unreadcount/" FROM /"" + strRootURI + "/""
                       + "</D:sql></D:searchrequest>";
                    // 创建新的CredentialCache对象,构建身份凭据
                    MyCredentialCache = new System.Net.CredentialCache();
                    MyCredentialCache.Add(new System.Uri(strRootURI), "NTLM",
                    new System.Net.NetworkCredential(strUserName, strPassword, strDomain));
                    // Create the HttpWebRequest object.
                    Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
                    // 指定HttpWebRequest的身份凭据,此处为关键所在。如果使用之前
                    // 创建的MyCredentialCache,则这个身份凭据是可以从Web服务器传递
                    // 到Exchange服务器的,但是这样带来的问题也很明显,就是不能够自
                    // 动获取当前登录到域的用户的身份。即便已经成功登录到域,那也只
                    // 能通过form再次输入用户名密码。因此,我在这里用的是
                    // Request.Credentials = CredentialCache.DefaultCredentials,
                    // 这样便可以获得当前用户的凭据,但是这样带来的问题便是上面提到的
                    // 身份凭据无法传递的问题,解决方法请关注下篇文章。
                    Request.Credentials = MyCredentialCache;
                    // 指定WebDAV的SEARCH方法
                    Request.Method = "SEARCH";
                    // Encode the body using UTF-8.
                    bytes = Encoding.UTF8.GetBytes((string)strQuery);
                    // Set the content header length. This must be
                    // done before writing data to the request stream.
                    Request.ContentLength = bytes.Length;
                    // Get a reference to the request stream.
                    RequestStream = Request.GetRequestStream();
                    // Write the SQL query to the request stream.
                    RequestStream.Write(bytes, 0, bytes.Length);
                    // Close the Stream object to release the connection
                    // for further use.
                    RequestStream.Close();
                    // Set the content type header.
                    Request.ContentType = "text/xml";
                    // Send the SEARCH method request and get the
                    // response from the server.
                    Response = (HttpWebResponse)Request.GetResponse();
                    // Get the XML response stream.
                    ResponseStream = Response.GetResponseStream();
                    // 创建XmlDocument对象,并获取收件箱的unreadcount节点的值
                    ResponseXmlDoc = new XmlDocument();
                    ResponseXmlDoc.Load(ResponseStream);
                    HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname");
                    SizeNodes = ResponseXmlDoc.GetElementsByTagName("d:unreadcount");
                    for (int i = 0; i < HrefNodes.Count; i++)
                    {
                        if (HrefNodes[i].InnerText == "收件箱")
                            count = int.Parse(SizeNodes[i].InnerText);
                    }
                    ResponseStream.Close();
                    Response.Close();
                }
                catch (Exception ex)
                {
                    // Catch any exceptions. Any error codes from the SEARCH
                    // method request on the server will be caught here, also.
                    return -1;
                }
                return count;
            }

    CSDN上的一篇博文或许对你有帮助。

    http://blog.csdn.net/showilove/article/details/4478101

    Thanks,

    Jack

    2012年5月29日 4:58
    版主

全部回复

  • 另: Creating OWA URL from EWS Response http://www.mombu.com/microsoft/exchange-server-development/t-creating-owa-url-from-ews-response-632192.html

    byte[] prEntryID = System.Convert.FromBase64String(miMailboxItem.Item Id.Id);
    byte[] owaLink = new byte[72];
    owaLink[0] = 70;
    owaLink[71] = 9;
    int owaval = 1;
    for (int sl = 43; sl <= prEntryID.Length-1; sl++)
    {
    owaLink[owaval] = prEntryID[sl];
    owaval++;
    }
    xrXmlWritter.WriteElementString("link", "https://" + snServerName + 
    "/owa/?ae=Item&t=IPM.Note&id=" + 
    Server.UrlEncode(Convert.ToBase64String(owaLink))) ;
    该方法也不对.


    Anything is Possible!

    2012年5月24日 4:38
  • Hi Harvey,

    这里有一个方法可以获取一个OWAID。

       //Get the OWA Id     
    public String GetOutlookOwaId(EmailMessage message, ExchangeService ser)  
       {        
     AlternateId ewsId = new AlternateId(IdFormat.EwsId, message.Id.ToString(), "person@example.com"); 
     AlternateIdBase owaId = ser.ConvertId(ewsId, IdFormat.OwaId);         
    return ((AlternateId)owaId).UniqueId;  
       }     

    以上方法来自英文连接,你可以参考一下。

    http://stackoverflow.com/questions/9175060/link-to-specific-email-in-exchange-2010-ews

    Thanks,

    Jack

    2012年5月25日 7:49
    版主
  • Hi, jack .

    谢谢你的答复《 稍后将测试.


    Anything is Possible!

    2012年5月29日 1:50
  • hi, jack.

    由于我使用的 ExchangeServiceBinding 这种方式来获取的《 

    下面这个类似

    ConvertIdType IdConverter = new ConvertIdType(); 
    IdConverter.DestinationFormat = IdFormatType.OwaId; 
     
    IdConverter.SourceIds = new AlternateIdType[1]; 
     
    AlternateIdType IdToConvert = new AlternateIdType(); 
    IdToConvert.Format = IdFormatType.EwsId; 
    IdToConvert.Mailbox = sender
    IdToConvert.Id = message.MessageType.ItemId.Id; 
    IdConverter.SourceIds[0] = IdToConvert; 
                     
    ConvertIdResponseType cIDResponse = svc.ConvertId(IdConverter); 


    Anything is Possible!

    2012年5月29日 3:27
  • Hi harvey,

    下面的方法不知道你有没有尝试过。

    private int GetUnReadMailCount()
            {
                string url = "http://10.10.10.254/exchange/"; //指定Exchange服务器地址 
                System.Net.HttpWebRequest Request;
                System.Net.WebResponse Response;
                System.Net.CredentialCache MyCredentialCache;
                string strUserName = UserName; //指定登录的用户名
                string strRootURI = url + strUserName; //得到要访问邮箱的WebDAV地址
                string strPassword = PassWord; //指定该用户的密码
                string strDomain = "unique.com"; //指定域名
                string strQuery = "";
                byte[] bytes = null;
                System.IO.Stream RequestStream = null;
                System.IO.Stream ResponseStream = null;
                XmlDocument ResponseXmlDoc = null;
                XmlNodeList HrefNodes = null;
                XmlNodeList SizeNodes = null;
                int count = 0;
                try
                {
                    // 用SQL查询WebDAV返回结果中的unreadcount节点.
                    strQuery = "<?xml version=/"1.0/"?><D:searchrequest xmlns:D = /"DAV:/" >"
                         + "<D:sql>SELECT /"DAV:displayname/",/"urn:schemas:httpmail:unreadcount/" FROM /"" + strRootURI + "/""
                       + "</D:sql></D:searchrequest>";
                    // 创建新的CredentialCache对象,构建身份凭据
                    MyCredentialCache = new System.Net.CredentialCache();
                    MyCredentialCache.Add(new System.Uri(strRootURI), "NTLM",
                    new System.Net.NetworkCredential(strUserName, strPassword, strDomain));
                    // Create the HttpWebRequest object.
                    Request = (System.Net.HttpWebRequest)HttpWebRequest.Create(strRootURI);
                    // 指定HttpWebRequest的身份凭据,此处为关键所在。如果使用之前
                    // 创建的MyCredentialCache,则这个身份凭据是可以从Web服务器传递
                    // 到Exchange服务器的,但是这样带来的问题也很明显,就是不能够自
                    // 动获取当前登录到域的用户的身份。即便已经成功登录到域,那也只
                    // 能通过form再次输入用户名密码。因此,我在这里用的是
                    // Request.Credentials = CredentialCache.DefaultCredentials,
                    // 这样便可以获得当前用户的凭据,但是这样带来的问题便是上面提到的
                    // 身份凭据无法传递的问题,解决方法请关注下篇文章。
                    Request.Credentials = MyCredentialCache;
                    // 指定WebDAV的SEARCH方法
                    Request.Method = "SEARCH";
                    // Encode the body using UTF-8.
                    bytes = Encoding.UTF8.GetBytes((string)strQuery);
                    // Set the content header length. This must be
                    // done before writing data to the request stream.
                    Request.ContentLength = bytes.Length;
                    // Get a reference to the request stream.
                    RequestStream = Request.GetRequestStream();
                    // Write the SQL query to the request stream.
                    RequestStream.Write(bytes, 0, bytes.Length);
                    // Close the Stream object to release the connection
                    // for further use.
                    RequestStream.Close();
                    // Set the content type header.
                    Request.ContentType = "text/xml";
                    // Send the SEARCH method request and get the
                    // response from the server.
                    Response = (HttpWebResponse)Request.GetResponse();
                    // Get the XML response stream.
                    ResponseStream = Response.GetResponseStream();
                    // 创建XmlDocument对象,并获取收件箱的unreadcount节点的值
                    ResponseXmlDoc = new XmlDocument();
                    ResponseXmlDoc.Load(ResponseStream);
                    HrefNodes = ResponseXmlDoc.GetElementsByTagName("a:displayname");
                    SizeNodes = ResponseXmlDoc.GetElementsByTagName("d:unreadcount");
                    for (int i = 0; i < HrefNodes.Count; i++)
                    {
                        if (HrefNodes[i].InnerText == "收件箱")
                            count = int.Parse(SizeNodes[i].InnerText);
                    }
                    ResponseStream.Close();
                    Response.Close();
                }
                catch (Exception ex)
                {
                    // Catch any exceptions. Any error codes from the SEARCH
                    // method request on the server will be caught here, also.
                    return -1;
                }
                return count;
            }

    CSDN上的一篇博文或许对你有帮助。

    http://blog.csdn.net/showilove/article/details/4478101

    Thanks,

    Jack

    2012年5月29日 4:58
    版主