编程语言
首页 > 编程语言> > 使用Java API从Lotus Notes NSF文件中提取电子邮件消息

使用Java API从Lotus Notes NSF文件中提取电子邮件消息

作者:互联网

我想使用Java API(Notes.jar),我正在运行安装了Lotus Notes 8.5的Windows机器.

我对Lotus Notes一无所知,我只需要做一个狭窄的任务:从NSF文件中提取电子邮件.我希望能够遍历所有电子邮件消息,获取元数据(From,To,Cc等)或原始MIME(如果可用).

我已经搜索了很多,但我没有找到任何简单的东西,而不需要一些重要的Lotus Notes领域专业知识.

一些示例代码让我开始将非常感谢.谢谢!

更新:我发现了一个在Python中执行此操作的开源项目:

http://code.google.com/p/nlconverter/

但是,仍然在寻找一种在Java中执行此操作的方法.

解决方法:

您可以编写一个简单的Java应用程序来获取您感兴趣的邮件数据库的句柄,然后获取该数据库中标准视图的句柄,然后迭代视图中的文档.这是一些(粗略的)示例代码:

import lotus.domino.*;
public class sample extends NotesThread
{
  public static void main(String argv[])
    {
        sample mySample = new sample();
        mySample.start();
    }
  public void runNotes()
    {
    try
      {
        Session s = NotesFactory.createSession();
        Database db = s.getDatabase ("Server", "pathToMailDB.nsf");
        View vw = db.getView ("By Person");  // this view exists in r8 mail template; may need to change for earlier versions
        Document doc = vw.getFirstDocument();
        while (doc != null) {               
            System.out.println (doc.getItemValueString("Subject"));
            doc = vw.getNextDocument(doc);
        }
      }
    catch (Exception e)
      {
        e.printStackTrace();
      }
    }
}

getItemValueString方法获取给定的“字段”值.邮件文档上的其他重要字段包括:From,SendTo,CopyTo,BlindCopyTo,Subject,Body和DeliveredDate.请注意,Body是Notes“富文本”项,getItemValueString将返回纯文本部分. DeliveredDate是一个NotesDate项,您需要使用getItemValueDateTimeArray方法.

标签:java,lotus-notes
来源: https://codeday.me/bug/20190607/1192257.html