Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java EWS API-读取非默认邮箱_Java_Exchangewebservices_Ewsjavaapi - Fatal编程技术网

Java EWS API-读取非默认邮箱

Java EWS API-读取非默认邮箱,java,exchangewebservices,ewsjavaapi,Java,Exchangewebservices,Ewsjavaapi,我希望使用Java EWS API读取exchange服务器上的非默认邮箱,但我的代码有问题。以下是相关部分的摘录: ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); ExchangeCredentials credentials = new WebCredentials("<user>", "<pass>"); service.setCredentials(c

我希望使用Java EWS API读取exchange服务器上的非默认邮箱,但我的代码有问题。以下是相关部分的摘录:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials("<user>", "<pass>");
service.setCredentials(credentials);
service.setUrl(new URI("https://<URL>/EWS/Exchange.asmx"));
ItemView iview = new ItemView(3);
Mailbox mb = new Mailbox();
mb.setAddress("<mailbox_address>");
FolderId folderId = new FolderId(WellKnownFolderName.Root, mb);
FindItemsResults<Item> findResults = service.findItems(folderId, iview);
顺便说一句,我可以阅读我的默认邮箱,发送电子邮件,等等


你能给我个建议吗?提前谢谢

我相信您正在尝试访问一个邮箱,但使用的是另一个帐户的凭据。这可以通过模拟来解决

在更新版本的EWS中,这可以解决,也可以解决。我可能会指望第二个,并使主SMTP地址可配置为不同的环境

下面是在C#中使用EWS 2010的代码示例,因此您可能必须使用
setCredentials(credentials)
,以此类推:

代码示例EWS 2010

ExchangeServiceBinding binding = new ExchangeServiceBinding();
// Use this class instead of ExchangeService (!)
binding.Credentials = credentials;  
// etc    

binding.ExchangeImpersonation = new ExchangeImpersonationType();
binding.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType();
binding.ExchangeImpersonation.ConnectingSID.PrimarySmtpAddress = "<mailbox_address>";
ExchangeServiceBinding=新的ExchangeServiceBinding();
//使用此类而不是ExchangeService(!)
binding.Credentials=凭证;
//等
binding.ExchangeImpersonation=新的ExchangeImpersonationType();
binding.ExchangeImpersonation.ConnectionSid=新的ConnectionSidType();
binding.ExchangeImpersonation.ConnectionSid.PrimarySMTAddress=“”;
2007年EWS的文档

据报道,这似乎也应该在EWS2007 SP1中提供。请从文章中注意:

您必须将“ms Exch EPI模拟”权限设置为必须位于客户端访问服务器上,以用于执行模拟的服务帐户。此外,服务帐户必须在其将模拟的每个邮箱上授予“ms Exch EPI可能模拟”权限。如果要在存储、存储组、服务器或组织级别设置此权限,则此权限将继承到邮箱


此代码似乎是正确的,如果此代码适用于默认邮箱,则可能是某个权限错误

我正在使用类似的代码访问共享邮件组的邮件


我看到的唯一区别是->WellKnownFolderName.MsgFolderRoot而不是WellKnownFolderName.Root

您是否尝试过用3个参数重载
WebCredentials
构造函数?也许你错过了域名。你看到这个问题了吗:?在StackOverflow上似乎有几个非常类似的问题,其中一些问题与Exchange服务器配置的身份验证有关。我不知道我是否能帮你更多,因为我看不出你的代码有任何问题。事实上,我能够进行身份验证。e、 g.我可以访问我的默认邮箱。只有当我尝试访问一个非默认邮箱时,我才会收到上面的错误消息。啊,我错过了你在问题中写的。我还有一个问题想知道我是否理解正确:你的证书适用于一个电子邮件地址,但不适用于另一个?您是否尝试过为其他邮箱提供凭据(或者它们是相同的)?我认为,通常您必须使用某种模拟来查看其他电子邮件帐户。是的,默认邮箱和非默认邮箱的凭据相同。如何使用此API设置此ConnectionSid属性?我添加了行:service.setImpersonatedUserId(new ImpersonatedUserId(ConnectingIdType.SmtpAddress,mailbox_address));仍然是相同的错误。@bayerb我还有最后一步要告诉您:确保您用于模拟的用户在服务器上的配置如下:我希望这有帮助!如果没有,我没有建议:(不幸的是,我对服务器配置没有任何影响。我已经用python suds、c++-gsoap进行了尝试,这是第三次尝试失败。VB和c#不好,因为软件需要在linux上运行。无论如何,感谢您的帮助。
ExchangeServiceBinding binding = new ExchangeServiceBinding();
// Use this class instead of ExchangeService (!)
binding.Credentials = credentials;  
// etc    

binding.ExchangeImpersonation = new ExchangeImpersonationType();
binding.ExchangeImpersonation.ConnectingSID = new ConnectingSIDType();
binding.ExchangeImpersonation.ConnectingSID.PrimarySmtpAddress = "<mailbox_address>";