私は解決しようとしています。私は自分のユーザー 'myuser'をサービスメールボックス 'serviceMail'にアクセスできます。だから、これは私の個人的なメールボックスではなく、さまざまな目的のために電子メールを送信した私の会社の別のメールボックス設定です。私はOutlookにこのメールボックスを追加したので、私はそれにアクセスできることを知っています。私は自分のメールのために普通のように受信トレイをチェックすることができます。私はEWSを使って、 'serviceMail' Inboxの電子メールから添付ファイルを取得するC#プログラムを作成しようとしています。私はアイテムを見つけようとするときに "401 Unauthroized Access"を取得しています。私は間違って何をしていますか?私のコードは以下の通りです。ここで401 EWSを使用してメールボックスに接続するときの許可されていないアクセス
は私がサービスに接続しています方法です:
以下public ExchangeService ConnectToExchangeServer()
{
const string strMailbox = "[email protected]";
const string strLoginUser = "[email protected]";
const string strLogingUserpwd = "pwd";
const string strO365Url = "https://outlook.office365.com/EWS/Exchange.asmx";
try
{
exchange = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
exchange.Credentials = new WebCredentials(strLoginUser, strLogingUserpwd, "sabra.com");
// exchange.AutodiscoverUrl(strMailbox,RedirectionUrlValidationCallback);
exchange.Url = new Uri(strO365Url);
return exchange;
}
catch (Exception ex)
{
}
return exchange;
}
は「私はエラーを取得する項目に
ExchangeService service = ga.ConnectToExchangeServer();
TimeSpan ts = new TimeSpan(0, -1, 0, 0);
DateTime date = DateTime.Now.Add(ts);
SearchFilter.IsGreaterThanOrEqualTo filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, date);
if (service != null)
{
//FindItemsResults<Item> findResults = ga.exchange.FindItems(WellKnownFolderName.Inbox, filter, new ItemView(50));
//FindItemsResults<Item> findResults = ga.exchange.FindItems(WellKnownFolderName.Inbox,);
// Return a single item.
ItemView view = new ItemView(1);
string querystring = "HasAttachments:true Subject:'Message with Attachments' Kind:email";
// Find the first email message in the Inbox that has attachments. This results in a FindItem operation call to EWS.
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, querystring, view);
foreach (Item item in findResults)
{
EmailMessage message = EmailMessage.Bind(ga.exchange, item.Id);
if (message.HasAttachments && message.Attachments[0] is FileAttachment)
{
FileAttachment fileAttachment = message.Attachments[0] as FileAttachment;
//Change the below Path
fileAttachment.Load(@"D:\\QlikData\\Lean\\EmailExtract" + fileAttachment.Name);
// lblAttach.Text = "Attachment Downloaded : " + fileAttachment.Name;
}
else
{
// MessageBox.Show("No Attachments found!!");
}
}
if (findResults.Items.Count <= 0)
{
//lstMsg.Items.Add("No Messages found!!");
}
}
を見つけようとするためのコードで要求が失敗したリモートサーバーが返さ。エラー:(401)Unauthorized。 " FindItemsResultsのfindResults = service.FindItems(WellKnownFolderName.Inbox、querystring、view)コード行。
アイデア?