我已经在网上搜索了我认为的各种类型的解决方案,但是还没找到它,所以这里就是这样。
我的应用程序使用Exchange Web Services API 2.0,它旨在读取ProdSupport@company.com的电子邮件地址。该应用程序旨在读入ProdSupport的收件箱并将其移动到名为" Staging"的自定义创建文件夹中。我可以阅读ProdSupport的收件箱的电子邮件。
问题是,当我遍历FindFolders()时,我不知道如何阅读ProdSupport的电子邮件文件夹列表。我见过的所有示例都使用了WellKnownFolderName,但这不适用于自定义文件夹。当我移动电子邮件时,它会将它从ProdSupport的收件箱移动到我的本地(myEmailaddress@company.com)Staging Email文件夹而不是ProdSupport的Staging Email文件夹。关于发生了什么的任何想法?
我尝试将FindFesults变量的parentFolderId(我认为是根文件夹)字符串传递给FolderID对象并使用FindFolders()但没有得到任何结果。我需要知道如何导航并访问此自定义"暂存电子邮件" ProdSupport@company.com的文件夹
我拥有所有访问权限,因为我可以创建文件夹/修改名称ProdSupport,因为我是该组的一部分。希望我的解释没有造成任何混淆。代码如下:
enter code here
this.Service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
Service.UseDefaultCredentials = false;
Service.Credentials = new WebCredentials("myUserID", "myPassword", "myOutlookDomain");
Mailbox ProdSupportMailbox = new Mailbox("ProdSupport@company.com");
Service.AutodiscoverUrl("ProdSupport@company.com");
View = new ItemView(40);
View.PropertySet = new PropertySet(BasePropertySet.FirstClassProperties,
EmailMessageSchema.From,
EmailMessageSchema.IsRead);
FindResults = Service.FindItems(new FolderId(WellKnownFolderName.Inbox, ProdSupportMailbox), View);
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
FolderView = new FolderView(100);
FolderView.PropertySet = new PropertySet(BasePropertySet.IdOnly);
FolderView.PropertySet.Add(FolderSchema.DisplayName);
FolderView.Traversal = FolderTraversal.Deep;
foreach (Folder folder in rootfolder.FindFolders(FolderView))
{
if (folder.DisplayName == "Staging Folder") // I cannot read this folder that I need access to for ProdSupport@company.com
// if (folder.DisplayName == "Staging Email local") // I can read this folder which is my local folder name(myEmailAddress@company.com)
{
stores it in a variable
var fid = folder.Id;
Console.WriteLine(fid);
}
答案 0 :(得分:0)
要访问NonWellKnown文件夹,您需要使用FindFolder操作查找该文件夹,访问您需要使用FolderId重载来指定您要访问的邮箱的另一个邮箱,例如我就是这样做的
internal static Folder FolderFromPath(ExchangeService service, String FolderPath, String MailboxName)
{
FolderId RootFolderId = new FolderId(WellKnownFolderName.MsgFolderRoot, MailboxName);
Folder RootFolder = Folder.Bind(service, RootFolderId);
String[] faFldArray = FolderPath.Split('\\');
Folder tfTargetFolder = RootFolder;
for (int lint = 1; lint < faFldArray.Length; lint++)
{
if (faFldArray[lint].Length != 0)
{
FolderView fview = new FolderView(1);
SearchFilter sf = new SearchFilter.IsEqualTo(FolderSchema.DisplayName, faFldArray[lint]);
FindFoldersResults ffResult = service.FindFolders(tfTargetFolder.Id, sf, fview);
if (ffResult.TotalCount == 0)
{
throw new Exception("Folder Not Found");
}
else
{
tfTargetFolder = ffResult.Folders[0];
}
}
}
return tfTargetFolder;
}
然后使用
Folder CopyTarget = FolderFromPath(service, "\\Inbox\\test","user@domain.com");
干杯 格伦
答案 1 :(得分:0)
感谢您的帮助Glen。事实证明我只是指向错误的上下文,我只需将FolderID指向与收件箱相同的邮箱:
FindResults = Service.FindItems(new FolderId(WellKnownFolderName.Inbox,ProdSupportMailbox),View);
FolderView只是一个具有设置属性的空对象。
var FolderResults = Service.FindFolders(new FolderId(WellKnownFolderName.Root,ProdSupportMailbox),FolderView);