views:

1419

answers:

1

I'd like to use the Java API (Notes.jar), and I'm running a Windows box with Lotus Notes 8.5 installed.

I know nothing about Lotus Notes, and I only need to do this one narrow task: extracting email messages from an NSF file. I want to be able to iterate through all the email messages, grab the metadata (From, To, Cc, etc) or the raw MIME if available.

I've googled around quite a bit, but I haven't found anything straightforward without requiring some significant Lotus Notes domain expertise.

Some sample code to get me started would be greatly appreciated. Thanks!

UPDATE: I found an open source project that does this in Python:

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

However, still looking for a way to do this in Java.

+2  A: 

You can write a simple Java app which gets a handle to the mail database you are interested in, then gets a handle to a standard view in that database, and then iterates over the documents in the view. Here is some (rough) sample code:

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();
      }
    }
}

The getItemValueString method gets a given "field" value. Other important fields on a mail document are: From, SendTo, CopyTo, BlindCopyTo, Subject, Body and DeliveredDate. Note that Body is a Notes "rich text" item, and getItemValueString will return the text-only portion. DeliveredDate is a NotesDate item, and you would need to use the getItemValueDateTimeArray method for that.

Ed Schembor