在 Lotus Notes 中使用 C# 将电子邮件保存为 eml

2023-12-20

我需要将 Lotus Notes 电子邮件导出(保存到)硬盘。 我找到了如何将附件保存到硬盘的方法,但我不知道如何保存整个电子邮件的方法。

下面的代码显示了我如何导出附件。您能建议我如何修改它以保存电子邮件吗? PS-我是编程新手。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domino;
using System.Collections;

namespace ExportLotusAttachments
{
  class Class1
  {
    public void ScanForEmails()
    {
      String textBox1 = "c:\\1";
      NotesSession session = new NotesSession();
      session.Initialize("");
      NotesDbDirectory dir = null;
      dir = session.GetDbDirectory("");
      NotesDatabase db = null;
      db = dir.OpenMailDatabase();
      NotesDatabase NDb = dir.OpenMailDatabase(); //Database connection

      //ArrayList that will hold names of the folders
      ArrayList LotusViews2 = new ArrayList(); 

      foreach (NotesView V in NDb.Views)
      {
        if (V.IsFolder && !(V.Name.Equals("($All)")))
        {
          NotesView getS = V;
          LotusViews2.Add(getS.Name);
        }
      }

      foreach (String obj in LotusViews2)
      {
        NotesDocument NDoc;
        NotesView nInboxDocs = NDb.GetView(obj);
        NDoc = nInboxDocs.GetFirstDocument();
        String pAttachment;

        while (NDoc != null)
        {
          if (NDoc.HasEmbedded && NDoc.HasItem("$File"))
          {
            object[] AllDocItems = (object[])NDoc.Items;
            foreach (object CurItem in AllDocItems)
            {
              NotesItem nItem = (NotesItem)CurItem;
              if (IT_TYPE.ATTACHMENT == nItem.type)
              {
                String path = textBox1;
                pAttachment = ((object[])nItem.Values)[0].ToString();

                if (!System.IO.Directory.Exists(path))
                {
                  System.IO.Directory.CreateDirectory(textBox1);
                }

                try
                {
                  NDoc.GetAttachment(pAttachment).ExtractFile(@path + pAttachment);
                }
                catch { }
              }
            }
          }
          NDoc = nInboxDocs.GetNextDocument(NDoc);
        }
      }
    }
  }
}

This http://www.bobzblog.com/tuxedoguy.nsf/dx/geek-o-terica-15-easy-conversion-of-notes-documents-to-mime-format-part-1发帖者鲍勃·巴拉班 http://www.bobzblog.com/解释如何使用 Java 导出 Lotus 文档。同样的原理也适用于 C# 或 VB。该文档被转换为 MIME 并写入磁盘。

或者在版本 8.5.3 中(我认为它是从 8.5.1 开始的),您可以将其从邮件文件拖放到文件系统中。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Lotus Notes 中使用 C# 将电子邮件保存为 eml 的相关文章

随机推荐