zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    LayoutInflater
    android 顶部的通知栏
    ..搞Android了
    数据分组取最大值行
    decode、sign、case在统计中的用法:
    Row generator
    存储过程包实例分享
    Bind variables in 'in' condition(在in中动态的绑定参数(参数个数可变))
    WM_CONCAT字符超过4000的处理办法
    oracle script
  • 原文地址:https://www.cnblogs.com/q149072205/p/14273115.html
Copyright © 2011-2022 走看看