最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

vsto - How to read emails in Outlook - Stack Overflow

programmeradmin3浏览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.

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.

Share Improve this question asked 20 hours ago E ZhangE Zhang 1717 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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.

发布评论

评论列表(0)

  1. 暂无评论