为什么我不能使用互操作 Outlook 检索所有邮件项目?

编程入门 行业动态 更新时间:2024-10-09 04:24:50
本文介绍了为什么我不能使用互操作 Outlook 检索所有邮件项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Microsoft.Office.Interop.Outlook 从我的 Outlook 收件箱中检索电子邮件.这是我的代码:

I'm trying to use Microsoft.Office.Interop.Outlook to retrieve emails from my Outlook inbox. This is my code:

  Application app = new Application();
  NameSpace ns = app.Session;
  MAPIFolder inbox = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
  Items items = inbox.Items;
  foreach (Microsoft.Office.Interop.Outlook.MailItem mail in items)
        {
            if (mail as MailItem != null)
            {
                Console.WriteLine(mail.Subject.ToString());
                Console.WriteLine(mail.Body.ToString());
                Console.ReadKey();
             }
        }

当我这样做时,它起作用了 - 有点.它只显示一封电子邮件.应该是三个.它显示的电子邮件是那里最古老的电子邮件......为什么我不能得到所有三个?除了 MailItem 之外,我的收件箱中还有其他类型的邮件吗?

When I do this, it works--sort of. It only shows one email. There should be three. The email it's showing is the oldest one in there... why wouldn't I be able to get all three? Is there some other type of mail besides MailItem that would be in my inbox?

推荐答案

我遇到了同样的问题 - 我的解决方法只是创建一个 List 并循环遍历它.但请确保电子邮件不在子文件夹中,否则将无法找到.

I had this same exact problem - My workaround was just to create a List<MailItem> and loop through that. Make sure the emails aren't in subfolders though, otherwise they won't be found.

Outlook.Application app = new Outlook.Application();
Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");
Outlook.MAPIFolder emailFolder = outlookNs.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

List<MailItem> ReceivedEmail = new List<MailItem>(); 
foreach (Outlook.MailItem mail in emailFolder.Items)               
    ReceivedEmail.Add(mail);

foreach (MailItem mail in ReceivedEmail)
{
    //do stuff
}

这篇关于为什么我不能使用互操作 Outlook 检索所有邮件项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-29 12:36:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/756982.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我不   邮件   操作   项目   Outlook

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!