Microsoft Exchange Web Services reading my local O

2019-09-09 03:17发布

I've searched for what I think is every type of solution on the net but haven't found it, so here goes.

My application uses Exchange Web Services API 2.0 and it's designed to read the Email address of ProdSupport@company.com. The app is designed to read into ProdSupport's Inbox and move it to a Custom created folder called "Staging". I AM ABLE to read into the emails of ProdSupport's Inbox.

Problem is, I don't know how to read into ProdSupport's list of email folders when I iterate through FindFolders(). All the examples I've seen use WellKnownFolderName but this won't work for a Custom Folder. When I do move an email, it moves it from the ProdSupport's Inbox to MY local(myEmailaddress@company.com) Staging Email folder instead of ProdSupport's Staging Email folder. Any ideas on what's happening?

I've tried passing the parentFolderId(which I thought was the Root Folder) string of the FindResults variable to a FolderID object and using FindFolders() but get no results. I need to know how to navigate to and access this custom "Staging Email" folder of ProdSupport@company.com

I have all access rights as I can create folders/modify names ProdSupport as I'm part of the Group. Hopefully I didn't create any confusion by my explanation. Code below:

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);


                }

2条回答
Summer. ? 凉城
2楼-- · 2019-09-09 03:59

Thanks for your help Glen. Turns out I was just pointing to the wrong context and I just needed to point the FolderID to the same Mailbox as the Inbox in:

FindResults = Service.FindItems(new FolderId(WellKnownFolderName.Inbox, ProdSupportMailbox), View);

FolderView was just an empty object with set properties.

var FolderResults = Service.FindFolders(new FolderId(WellKnownFolderName.Root, ProdSupportMailbox), FolderView);

查看更多
迷人小祖宗
3楼-- · 2019-09-09 04:00

To access a NonWellKnown folder you need to use the FindFolder operation to find that folder, to access another mailbox you need to use the FolderId overload to specify the Mailbox you want to access eg this is how I do it

        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;
    }

then use

Folder CopyTarget = FolderFromPath(service, "\\Inbox\\test","user@domain.com");

Cheers Glen

查看更多
登录 后发表回答