I am trying to save email on office 365 using Microsoft.Exchange.WebServices.dll (EWS Apis)
EmailMessage f_ObjEWSMail = new EmailMessage(objExchangeService);
f_ObjEWSMail.Save(p_objFoderID); // Throwing error here
It throws exception randomly :
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
at System.Net.Security._SslStream.EndRead(IAsyncResult asyncResult)
at System.Net.TlsStream.EndRead(IAsyncResult asyncResult)
at System.Net.PooledStream.EndRead(IAsyncResult asyncResult)
at System.Net.Connection.ReadCallback(IAsyncResult asyncResult)
or sometimes it throws:
The request failed. The underlying connection was closed: An unexpected error occurred on a receive.
Stack Strace :: at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.GetEwsHttpWebResponse(IEwsHttpWebRequest request) at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ValidateAndEmitRequest(IEwsHttpWebRequest& request) at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest
1.Execute() at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalCreateItems(IEnumerable
1 items, FolderId parentFolderId, Nullable1 messageDisposition, Nullable
1 sendInvitationsMode, ServiceErrorHandling errorHandling) at Microsoft.Exchange.WebServices.Data.Item.InternalCreate(FolderId parentFolderId, Nullable1 messageDisposition, Nullable
1 sendInvitationsMode) at Microsoft.Exchange.WebServices.Data.Item.Save(FolderId parentFolderId) at Office365EWSWriter.Office365Engine.SaveMail(EmailMessage p_objEWSMailItem, FolderId p_objFoderID)
Please suggest solution.
MailMessageObj
in the above code? and you are fetching mail message from which mail account? – sujith karivelil