在Outlook Addin中获取传入电子邮件的正文

thi*_*ool 4 c# email outlook

我想处理来自Exchange服务器的传入邮件并将其保存在我的邮箱中.截至目前,我可以收到每封收到邮件的提醒.

如何获取电子邮件的正文以进行处理?

   public partial class ThisAddIn
   {
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.NewMail += new ApplicationEvents_11_NewMailEventHandler(AlertWhenNewMail);
            }
            void AlertWhenNewMail()
            {
                MessageBox.Show("New Email Recieved");
            }

            private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
            {
            }
            #region VSTO generated code
            private void InternalStartup()
            {
               this.Startup += new System.EventHandler(ThisAddIn_Startup);
               this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
            }
            #endregion
    }
Run Code Online (Sandbox Code Playgroud)

另外,如何保存电子邮件,然后将其存储在收件箱文件夹中?

Pau*_*Jan 5

要获取实际的mailItem,请使用newMailEx事件中传递的entryID.您对其他帖子的回复表明这对您不起作用,但我会假设我们会解决这个问题并为您提供一些示例代码:

void MyApplication_NewMailEx(string anEntryID)
{
  Outlook.NameSpace namespace = this.GetNamespace("MAPI");  
  Outlook.MAPIFolder folder = this.Session.GetDefaultFolder( Outlook.OlDefaultFolders.olFolderInbox );
  Outlook.MailItem mailItem = (Outlook.MailItem) outlookNS.GetItemFromID( anEntryID, folder.StoreID );

  // ... process the mail item
}
Run Code Online (Sandbox Code Playgroud)

要回答问题的第二部分,一旦您通过此事件获取邮件项目,它就已经保存到您的收件箱中,因此无需在那里做任何事情.您可以使用MailItem.SaveAs将其保存到磁盘.