Microsoft Exchange Web Services正在读取我的本地Outlook文件夹,而不是另一个地址

本文关键字:文件夹 Outlook 地址 另一个 Services Web Exchange 我的 读取 Microsoft | 更新日期: 2023-09-27 18:11:05

我已经在网上搜索了我认为是每种类型的解决方案,但还没有找到,所以这里开始。

我的应用程序使用Exchange Web Services API 2.0,它被设计为读取ProdSupport@company.com的电子邮件地址。该应用程序的目的是读到ProdSupport的收件箱,并将其移动到一个自定义创建的文件夹称为"分期"。我能够读到ProdSupport的收件箱的电子邮件。

问题是,当我迭代FindFolders()时,我不知道如何读取ProdSupport的电子邮件文件夹列表。我看到的所有例子都使用了WellKnownFolderName,但这对自定义文件夹不起作用。当我移动电子邮件,它从ProdSupport的收件箱移动到我的本地(myEmailaddress@company.com)分期电子邮件文件夹,而不是ProdSupport的分期电子邮件文件夹。有什么想法吗?

我试过传递parentFolderId(我认为是根文件夹)字符串的FindResults变量的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);

                }

Microsoft Exchange Web Services正在读取我的本地Outlook文件夹,而不是另一个地址

要访问一个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");

干杯格伦

谢谢你的帮助Glen。原来我只是指向了错误的上下文,我只需要将FolderID指向与Inbox相同的Mailbox:

FindResults = Service。FindItems(新FolderId (WellKnownFolderName。Inbox, ProdSupportMailbox), View);

FolderView只是一个设置属性的空对象。

var FolderResults = Service。FindFolders(新FolderId (WellKnownFolderName。