I m getting this error : The request failed. The underlying connection was closed: An unexpected error occurred on a receive.
when im trying to read email from exchange server using EWS this is my code :
try {
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ServicePointManager.MaxServicePoints =1000;
ServicePointManager.MaxServicePointIdleTime = 10000;
ServicePointManager.UseNagleAlgorithm = true;
ServicePointManager.Expect100Continue = true;
ServicePointManager.DefaultConnectionLimit = 10000;
var exchange = new ExchangeService(ExchangeVersion.Exchange2013);
exchange.Credentials = new WebCredentials("user", "password", "domain");
exchange.TraceEnabled = true;
exchange.TraceFlags = TraceFlags.All;
exchange.AutodiscoverUrl("mail-id", RedirectionUrlValidationCallback);
exchange.Url = new System.Uri("https://URL/EWS/Exchange.asmx");
exchange.KeepAlive = false;
exchange.Timeout = 900000;
WriteToFile("Connected to Exchange Server : " + exchange.Url.Host);
TimeSpan ts = new TimeSpan(0, 0, -15, 0);
DateTime date = DateTime.Now.Add(ts);
SearchFilter.IsGreaterThanOrEqualTo filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, date);
if (exchange != null)
{
FindItemsResults<Item> findResults = exchange.FindItems(WellKnownFolderName.Inbox, filter, new ItemView(999));
foreach (Item item in findResults)
{
EmailMessage message2 = EmailMessage.Bind(exchange,
(EmailMessage.Bind(exchange, item.Id)).Id,
new PropertySet(BasePropertySet.FirstClassProperties,
new ExtendedPropertyDefinition(0x1013, MapiPropertyType.Binary)));
var mailbosy = message2.Body.Text;
}
I confirm what @Glen Scales says. The MSI download and NuGet downloads don't work. You must recompile from source.