• c#收取获取outlook中的邮件内容


    界面如下:

    直接上代码如下:

    Microsoft.Office.Interop.Outlook.Application myOutlookApp = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.NameSpace myNameSpace = myOutlookApp.GetNamespace("MAPI");
                //本地邮箱
                Microsoft.Office.Interop.Outlook.MAPIFolder myFolderInbox = myNameSpace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);//获取收件箱对象,如获取其他箱可在参数中控制
                //Microsoft.Office.Interop.Outlook.MAPIFolder myFolder = myFolderInbox.Folders["xx"];//“xx”为收件箱下的一个文件夹
                //Microsoft.Office.Interop.Outlook.MAPIFolder MyParentFolder = myFolderInbox.Parent as Microsoft.Office.Interop.Outlook.MAPIFolder;//获取收件箱上一级的文件夹对象,以次来获取与收件箱同级的文件夹
                //Microsoft.Office.Interop.Outlook.MAPIFolder MyNewFolder = MyParentFolder.Folders["yy"];//“yy”为与收件箱同级的文件夹
    
                Microsoft.Office.Interop.Outlook.Items myMails = myFolderInbox.Items as Microsoft.Office.Interop.Outlook.Items;
                Console.WriteLine("mail Count:" + myMails.Count.ToString());
                int showCount = 0;
                for (int index = myMails.Count; index >0; index--) {
                    //倒序才是从最近的收到的邮件显示
                    Microsoft.Office.Interop.Outlook.MailItem myMail = myMails[index] as Microsoft.Office.Interop.Outlook.MailItem;
                    Console.WriteLine("======================================================");
                    Console.WriteLine("Subject:" + myMail.Subject.ToString());
                    Console.WriteLine("ReceivedTime:" + myMail.ReceivedTime.ToString());
                    Console.WriteLine("Body:" + myMail.Body.ToString().Substring(0,10));
                    showCount++;
                    if (showCount > 10) break;//只显示10封
                }

    记得添加引 using Microsoft.Office.Interop.Outlook;

    说明,

    如果是 office2010用14.0.0.0  

    如果是  office2013/2016用15.0.0.0 

    代码如下:https://files.cnblogs.com/files/q149072205/ReadEmailDemo.rar

  • 相关阅读:
    SpringBoot之集成Socket
    SpringBoot之集成WebSocket
    SpringBoot之统一异常处理
    请求的转发和重定向
    5+App使用定位
    将Tomcat注册为Windows服务
    Tomcat环境变量设置
    CentOS7搭建Gitlab详细过程
    Python 12 内置函数
    Python 11 生成器
  • 原文地址:https://www.cnblogs.com/q149072205/p/14273115.html
Copyright © 2020-2023  润新知