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