gpt4 book ai didi

java - 从自定义文件夹中读取 MSExchange 电子邮件

转载 作者:行者123 更新时间:2023-12-01 10:08:19 24 4
gpt4 key购买 nike

有没有办法使用 Java 从 MS-Exchange 中的自定义文件夹中读取电子邮件?我可以从收件箱中读取内容,但我有自定义文件夹名称,电子邮件将移至其中,我希望在这些文件夹中读取代码。

下面是我当前从收件箱读取的代码:

ExchangeCredentials credentials = new WebCredentials("userName", "passWORD", "domain");
service.setCredentials(credentials);
service.setUrl(new URI("https://outlook.mycompany.com/ews/exchange.asmx"));

ItemView view = new ItemView(200);

FindItemsResults<Item> findResults = service.findItems(WellKnownFolderName.Inbox , view);

相反,我想要这样的东西:

FindItemsResults<Item> findResults = service.findItems("My Custom Folder" , view);

我已经尝试过这个,但没有成功:

FindItemsResults<Item> findResults = service.findItems(FolderId.getFolderIdFromString("My Custom Folder") , view);

最佳答案

您需要使用 FindFolder 操作来查找相关文件夹的 ewsId。通常,执行此操作的简单方法是将要访问的文件夹转换为路径,例如,如果该文件夹是收件箱的子文件夹,则路径字符串将是\Inbox\Subfolder 名称,那么您应该能够使用类似以下内容要拆分路径,请执行多个查找以获取您之后的特定文件夹(这是 C#,但您应该能够轻松转换为 java,因为类大部分相同)

    internal static Folder GetFolderFromPath(ExchangeService service,String MailboxName,String FolderPath)
{
FolderId folderid = new FolderId(WellKnownFolderName.MsgFolderRoot,MailboxName);
Folder tfTargetFolder = Folder.Bind(service,folderid);
PropertySet psPropset = new PropertySet(BasePropertySet.FirstClassProperties);
String[] fldArray = FolderPath.Split('\\');
for (Int32 lint = 1; lint < fldArray.Length; lint++) {
FolderView fvFolderView = new FolderView(1);
fvFolderView.PropertySet = psPropset;
SearchFilter SfSearchFilter = new SearchFilter.IsEqualTo(FolderSchema.DisplayName,fldArray[lint]);
FindFoldersResults findFolderResults = service.FindFolders(tfTargetFolder.Id,SfSearchFilter,fvFolderView);
if (findFolderResults.TotalCount > 0){
foreach(Folder folder in findFolderResults.Folders){
tfTargetFolder = folder;
}
}
else{
tfTargetFolder = null;
break;
}
}
if (tfTargetFolder != null)
{
return tfTargetFolder;
}
else
{
throw new Exception("Folder Not found");
}
}

干杯格伦

关于java - 从自定义文件夹中读取 MSExchange 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36315660/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com