0

We need to create widget that displays number of new/unread emails of current logged SharePoint user. Preferably using JSOM/Rest API for Javascript

We've done the following:

  • Link SharePoint to sync profiles from Active Directory (AD)
  • Configure SharePoint/Exchange server Single Sign-On (SSO)

1 Answer 1

1

I somehow figured to have a workaround

here is my web part C# code behind

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.DirectoryServices;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.SharePoint;

namespace Messagerie.WidgetVisualWebPart
{
    public partial class WidgetVisualWebPartUserControl : UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
            {

                if (errors == System.Net.Security.SslPolicyErrors.None)
                {
                    return true;
                }

                if ((errors & System.Net.Security.SslPolicyErrors.RemoteCertificateChainErrors) != 0)
                {
                    if (chain != null && chain.ChainStatus != null)
                    {
                        foreach (System.Security.Cryptography.X509Certificates.X509ChainStatus status in chain.ChainStatus)
                        {
                            if ((certificate.Subject == certificate.Issuer) &&
                               (status.Status == System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.UntrustedRoot))
                            {

                                continue;
                            }
                            else
                            {
                                if (status.Status != System.Security.Cryptography.X509Certificates.X509ChainStatusFlags.NoError)
                                {

                                    return false;
                                }
                            }
                        }
                    }

                    return true;
                }
                else
                {

                    return false;
                }
            };

            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
            service.EnableScpLookup = true;
            try
            {
                service.Credentials = new WebCredentials("[email protected]", "impersonateAccountPassword", System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName);
                service.Url = new Uri("https://mail.domain.com/EWS/Exchange.asmx");
                service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SID, SPContext.Current.Web.CurrentUser.UserId.NameId);

                Folder inbox = Folder.Bind(service, WellKnownFolderName.Inbox);
                // ...
            }
            catch (Exception exception)
            {
                ErrorMessage = exception.Message;
            }
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.