[英]C# Outlook reading subject
我的收件箱中的循環 function 有問題,它向我顯示了電子郵件的主題。
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”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.