【问题标题】:Save content of Email body in outlook to a file将Outlook中电子邮件正文的内容保存到文件中
【发布时间】:2012-01-04 03:26:11
【问题描述】:

我想将 Outlook 中电子邮件正文的内容保存到文件中。我能够保存整个消息 .msg 但我只想保存正文的 html 内容。 例如: 在 Outlook 电子邮件正文中,我有一个表格,我想将该表格保存到文件中。 我正在编写的脚本:

public void GetAttachments()
    {
       Microsoft.Office.Interop.Outlook.Application myolApp = default(Microsoft.Office.Interop.Outlook.Application);
       Microsoft.Office.Interop.Outlook.NameSpace ns = default(NameSpace);
       MAPIFolder Inbox = default(MAPIFolder);
       object Item = null;
       Attachment Atmt = default(Attachment);
       string FileName = null;
       string subject = null;
       string AttachmentName = null;
       string Body = null;
       string SenderName = null;
       string SenderEmailAddress = null;
       string CreationTime = null;
       int i = 0;
       int j = 0;
       try
       {

        myolApp = (Microsoft.Office.Interop.Outlook.Application)Interaction.CreateObject("Outlook.Application","");
        ns = myolApp.GetNamespace("MAPI");
        ns.Logon("", "", false, true);
        Inbox = ns.Folders["Mailbox - Name"].Folders["Inbox"];
        i = 0;
        j = 1;

        //Scan for attachments
        foreach (object Item_loopVariable in Inbox.Items) 
        {
           Item = Item_loopVariable;
           System.Windows.Forms.Application.DoEvents();

           if ((Item as MailItem) != null ? ((MailItem)Item).UnRead : false) 
           {
             Body = ((Microsoft.Office.Interop.Outlook.MailItem)Item).Body;
             ((Microsoft.Office.Interop.Outlook.MailItem)Item).HTMLBody = Body;
             ((Microsoft.Office.Interop.Outlook.MailItem)Item).SaveAs(@"\\path\"+"filename",                                       Microsoft.Office.Interop.Outlook.OlSaveAsType.olHTML   );

                  j = j + 1;

           }
        }



    //Clear Memory
    Atmt = null;
    Item = null;
    ns = null;

 }
      catch (System.Exception ex)
      {
            MessageBox.Show("An unexpected error has occurred." 
             + "\r\n" + "Please note and report the following information."
             + "\r\n" + "Script Name: GetAttachments"
             + "\r\n" + "Error Description: " + ex.Message
             + "\r\n" + "Error StackTrace: " + ex.StackTrace
                , "Error!");
            Atmt = null;
            Item = null;
            ns = null;
      }
}

我需要修改这些代码:

Body = ((Microsoft.Office.Interop.Outlook.MailItem)Item).Body;
             ((Microsoft.Office.Interop.Outlook.MailItem)Item).HTMLBody = Body;
             ((Microsoft.Office.Interop.Outlook.MailItem)Item).SaveAs(@"\\path\"+"filename",                                       Microsoft.Office.Interop.Outlook.OlSaveAsType.olHTML   );

【问题讨论】:

    标签: c# ssis outlook task


    【解决方案1】:

    就文件系统安全而言,Outlook 在保存电子邮件正文方面存在一些问题。一种解决方法是使用文件系统对象来保存正文 - 为我工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-11
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 2012-12-01
      • 2019-08-29
      • 1970-01-01
      • 2014-07-13
      相关资源
      最近更新 更多