How to access the document in a Mail arrived Lotusscript agent?

Hi,

I’m new to agent and want to create an “After mail has arrived” agent in Lotusscript.

Sub Initialize

Dim session As NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Dim item As NotesItem



Set session = New NotesSession

Set db = session.CurrentDatabase

Set doc = session.DocumentContext



doc.Subject = "hello"

Call doc.Save(True, False)

End Sub

I put the codes above in the Initialize procedure of an “After new mail has arrived” agent and choose Run from Agent menu. It reports “Object variable not set”.

How to access the newly arrived mail document ( get the handler of the doc )?

Thanks in advanced~

Subject: Thank you very much!

Thank you for the help!

Thank you! :}

Subject: How to access the document in a Mail arrived Lotusscript agent?

The short answer is that the two mail triggers access the documents to process differently.

You will find an article “Out of the inbox” in the Agent FAQ which compare two triggers side by side, with explanations of how they work and coding examples.

Subject: How to access the document in a Mail arrived Lotusscript agent?

The “after New mail arrives” agent is actually scheduled, frequently, but scheduled. It does not run every time a new document hits the database, but needs to pick up all docs that have come in since the last time it ran. Use a collection:

Dim session as New NotesSession

Dim db as NotesDatabase

Dim doc as NotesDocument

Dim collection as NotesDocumentCollection

Set db = session.CurrentDatabase

Set collection = db.UnprocessedDocuments

set doc = collection.GetFirstDocument

while not (doc is Nothing)

…do what you want here

set doc = collection.GetNextDocument (doc)

wend