c# - C# Outlook 阅读主题
问题描述
我的收件箱中的循环功能有问题,它向我显示了电子邮件的主题。
private void button3_Click(object sender, EventArgs e)
{
Outlook.Application OutlookApp = new Outlook.Application();
Outlook.NameSpace nameSpace = OutlookApp.GetNamespace("MAPI");
Outlook.MAPIFolder folderInbox = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.Folders inboxFolders = folderInbox.Folders;
Outlook.Items mails = folderInbox.Items;
Outlook.MAPIFolder subFolderInbox = null;
try
{
Console.WriteLine(" numarul de emailuri" + mails.Count);
foreach (Outlook.MailItem item in mails)
{
string subj = item.Subject;
MessageBox.Show(subj);
Console.WriteLine(subj);
Marshal.ReleaseComObject(item);
}
//subFolderInbox = inboxFolders.Add("LP History", Outlook.OlDefaultFolders.olFolderInbox);
}
catch (Exception exception)
{
if (exception.ErrorCode == -2147352567)
//cannot creat folder error
MessageBox.Show("Cannot creater folder error");
}
if (subFolderInbox != null) Marshal.ReleaseComObject(subFolderInbox);
if (inboxFolders != null) Marshal.ReleaseComObject(inboxFolders);
if (folderInbox != null) Marshal.ReleaseComObject(folderInbox);
if (nameSpace != null) Marshal.ReleaseComObject(nameSpace);
}
甚至没有进入 foreach 循环:我在控制台中生成的内容:“ numarul de emailuri340 'OLP.exe' (CLR v4.0.30319: OLP.exe): Loaded 'C:\windows\Microsoft.Net\assembly\GAC_32 \CustomMarshalers\v4.0_4.0.0.0__b03f5f7f11d50a3a\CustomMarshalers.dll'。跳过加载符号。模块已优化并启用调试器选项“仅我的代码”。抛出异常:OLP.exe 中的“System.InvalidCastException”
解决方案
推荐阅读
- r - 如何将散点图变成数字?
- javascript - 引导模式不会出现 (ID)
- kubernetes - 使用 Jenkins 通过 EKS 部署应用程序
- python - 创建查找并返回匹配数据的 Pandas 列
- javascript - 为什么用 ArcGIS API JS 加载 WMS 图层会那么慢?
- azure-ad-b2c - 验证 Azure AD B2C 自定义策略中的限制
- google-sheets - 如何在 Google 表格中使用 GETPIVOTDATA
- swift - 在 ZStack 中对齐对象
- onlyoffice - 在 onlyoffice 桌面应用程序上更改经纪人的语言
- python - 更新字典中的数组