I am trying to fetch e-mail messages in Domino using Java (DCO and Lotus Domino packages). I want to fetch messages with a given message ID from the user's inbox folder. How do I do that?
The Message ID is contained in the $MessageID field. For example, a newsletter from SearchDomino.com had the message ID "<20030702151524.57275282A@mailhost11.lists.techtarget.com>". To get a handle on this document in a users inbox, you could use the following code:
Sub Initialize
  Dim s As New NotesSession
  Dim db As NotesDatabase
  Dim view As NotesView
  Dim doc As NotesDocument
  Dim docNext As NotesDocument
  Dim item As NotesItem
  Dim strMessageID As String
  
  strMessageID =
 "<20030702151524.57275282A
@mailhost11.lists.techtarget.com>"
  
  Set db = s.GetDatabase("server", 
"mailfilename")
  Set view = "($InBox)"
  Set doc = view.GetFirstDocument
  While Not(doc Is Nothing)
    Set item = doc.GetFirstItem("$MessasgeID")
    If item.text = MessageID Then
      ' --- add whatever code you need to 
'process the document the way you wish
      ' --- possibly : Call doc.Remove
      Goto singleExit
    End If
    Set doc = dc.GetNextDocument(doc)
  Wend
  
singleExit:
  
End Sub

This was first published in September 2003