EWS Managed APIを使用して特定の日付の電子メールのリストを取得できる電子メールクライアントを作成しようとしていますが、Folder.Bind()を呼び出すと例外が発生します。スローFolder.Bind例外ArgumentNullExceptionが発生しました
例外:がmscorlib.dll 追加情報の 'System.ArgumentNullException':値をNullにすることはできません。
それは例外ArgumentNullExceptionだと言うが、1つのパラメータは、列挙型であり、他は、実行時にnullではありません。スタックからは、EWS APIの中で例外的に扱われているようですが、問題は何か分かりません。
ここに私のコードです。
//Get emails
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, getFrom));
var emails = ExchangeService.FindItems(WellKnownFolderName.Inbox, filter, new ItemView(int.MaxValue));
これは、両方のバージョン2.2.0およびEWSのAPIのSDKの1.2.0で行われます。このようなアイテムを入手する
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Integration
{
public class ExchangeEmailClient : EmailClientBase
{
public ExchangeEmailClient(string emailAddress, string password)
{
ExchangeService = new ExchangeService();
ExchangeService.Credentials = new WebCredentials(emailAddress, password);
ExchangeService.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
}
public ExchangeService ExchangeService { get; private set; }
public override IEnumerable<Email> Receive(DateTime getFrom)
{
//Get emails
var inbox = Folder.Bind(ExchangeService, WellKnownFolderName.Inbox); //Exception thrown here!
var filter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsGreaterThan(ItemSchema.DateTimeReceived, getFrom));
var emails = inbox.FindItems(filter, new ItemView(int.MaxValue));
//Transform (use data transformation tool?)
foreach (EmailMessage exchangeEmail in emails)
{
var standardEmail = new Email();
standardEmail.Body = exchangeEmail.Body;
standardEmail.Subject = exchangeEmail.Subject;
standardEmail.From = exchangeEmail.From.Address;
standardEmail.Attachments = exchangeEmail.Attachments.Select(x => new Uri(x.ContentLocation)).ToList();
standardEmail.CarbonCopy = exchangeEmail.CcRecipients.Select(x => x.Address).ToList();
yield return standardEmail;
}
}
public override void Send(Email email)
{
var outgoingMail = new EmailMessage(ExchangeService);
outgoingMail.Body = email.Body;
outgoingMail.Subject = email.Subject;
outgoingMail.From = new EmailAddress(email.From);
//Get attachments
email.Attachments.ForEach(x => outgoingMail.Attachments.AddFileAttachment(x.ToString()));
//Set addresses
email.To.ForEach(x => outgoingMail.ToRecipients.Add(new EmailAddress(x)));
email.CarbonCopy.ForEach(x => outgoingMail.CcRecipients.Add(new EmailAddress(x)));
email.BlindCarbonCopy.ForEach(x => outgoingMail.BccRecipients.Add(new EmailAddress(x)));
//Send
outgoingMail.SendAndSaveCopy();
}
}
}
は、同じ例外がスローされます。
@ mr_frostfire https://referencesource.microsoft.com/#System/net/System/Net/ServicePointManager.cs,82c3f783b86dc371 – pm100