2016-04-06 41 views
1

サービスアカウントを使用して「通知」電子メールアドレスの受信トレイにアクセスしようとしています。このサービスアカウントには、アカウントと同じアクセス許可がありますが、独自の電子メールアドレスはありません。単にサービスアカウントです。このコードは現在、単に「テストの対象を持っているどのように多くの電子メール受信トレイに表示されるはずですサービスアカウントを使用するC#とExchange Webサービス - エラー

When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.

:私は私のアカウントを使用する場合、私はサービスアカウントを使用する場合、以下のテストコードは動作しますが、しかし、私は次のエラーを取得します'私はこのサイトの多くの投稿の回答を試してみましたが、誰も働いていません。ご協力いただきありがとうございます。以下のコードです:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); 
service.Credentials = new WebCredentials("ServiceAccount", "Password"); 
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 
ItemView mView = new ItemView(10); 
mView.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending); 
string querystring = "subject:\"test\""; 
Console.WriteLine("Total emails whos subject is 'test':"); 
FindItemsResults<Item> results = service.FindItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox("[email protected]")), querystring, mView); 
Console.WriteLine(results.Items.Count.ToString()); 

UPDATE:

が、私はそれは私に別のエラーを与えることから、Noonandのコードを追加したいです。むしろメソッドを使用するよりも1つのブロックに収まるように編集するには、ここでのコードは次のとおりです。

ImpersonatedUserId impersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "smtp.mysmtpaddress.com"); 
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); 
service.Credentials = new NetworkCredential("ServiceAccount", "Password"); 
service.ImpersonatedUserId = impersonatedUserId; 
service.AutodiscoverUrl("[email protected]", RedirectionUrlValidationCallback); 
try 
{ 
    AlternateIdBase response = 
     service.ConvertId(new AlternateId(IdFormat.EwsId, "Placeholder", "[email protected]"), IdFormat.EwsId); 


} 
catch (ServiceResponseException) 
{ 
    // Expected exception, see EWS documentation 
    // Nonetheless, the credentials provided can authenticate successfully against this Exchange box 

} 
ItemView mView = new ItemView(10); 
mView.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending); 
string querystring = "subject:\"test\""; 
Console.WriteLine("Total emails whos subject is 'test':"); 
FindItemsResults<Item> results = service.FindItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox("[email protected]")), querystring, mView); 
Console.WriteLine(results.Items.Count.ToString()); 

私はそのコードを実行すると、私は「FindItemResults」行で以下のエラーが表示されます。

The SMTP address has no mailbox associated with it.

はUPDATE 2 :

Noonandのおかげで、このエラーはExchange Server 2013自体のバグだと思う。私は長い時間がかかる可能性があり、このアップデートを行う前に変更プロセスは私の会社で通り抜けるまで

https://support.microsoft.com/en-us/kb/3006861

私は待たなければならないが、私はそうそこにこれを出したかった:リンクについては下記を参照してください。同じ問題を抱えている人はこれを見て助けになるかもしれません。

答えて

0

このようなものはあなたのために働くはずです。これはメモ帳に入力されたものであり(誤字を許してください)、コンパイルされていません。正しいパスの下を移動するように意図されています。

public static ExchangeService ConnectToExchangeWithImpersonation(string userName, SecureString password, string impersonatedUserSmtpAddress, Uri serverUrl) 
{ 
    ImpersonatedUserId impersonatedUserId = 
     new ImpersonatedUserId(ConnectingIdType.SmtpAddress, impersonatedUserSmtpAddress); 

    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2) // Change as appropriate 
    { 
     Credentials = new NetworkCredential(userName, password); 
     ImpersonatedUserId = impersonatedUserId; 
     Url = serverUrl; 
    } 

    // Connected, now authenticate 
    try 
    { 
     AlternateIdBase response = 
      exchangeService.ConvertId(new AlternateId(IdFormat.EwsId, "Placeholder", userInformation.Username), IdFormat.EwsId); 

    } 
    catch (ServiceResponseException) 
    { 
     // Expected exception, see EWS documentation 
     // Nonetheless, the credentials provided can authenticate successfully against this Exchange box 
    } 

    return service; 
} 
+1

noonandを試していただきありがとうございます。しかし、そのコードを使用すると別のエラーが発生します。コードについては以下を参照してください。 –

+0

エラーが発生した場合は、こちらを参照してください。https://support.microsoft.com/en-us/kb/3006861 Exchange管理者をループさせる時間はと思います.-) – noonand

+1

AH HA!これはまさに問題が何であるかのように聞こえます。投稿を更新して、人々にリンクが表示されるようにします。 –

関連する問題