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);
}
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);
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
then use
Cheers Glen