0

I tried to read emails from an email Outlook account in a .pst/.ost file. The code is as follows.

Outlook.Application myApp = new Outlook.Application();
Outlook.NameSpace mapiNameSpace = myApp.GetNamespace("MAPI");

// Get the email account root folder
Outlook.MAPIFolder myEmail = mapiNameSpace.Folders[textBox_EmailBody_Account.Text.Trim()];

// Get the specific subfolder
Outlook.MAPIFolder emailFolder = (Outlook.MAPIFolder)myEmail.Folders[textBox_EmailBody_Folder.Text.Trim()];

It works fine for a .pst file, but fails for a .ost file (myEmail == null). The .pst file is in the folder "C:\Users\name\Documents\Outlook Files" and the .ost file is in "C:\Users\name\AppData\Local\Microsoft\Outlook". I need help on this. Thanks.

1 Answer 1

1

It means the top folder name does not match what you pass to mapiNameSpace.Folders[]. Look at the value of textBox_EmailBody_Account.Text and compare it to the folders names in the mapiNameSpace.Folders collection.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.