Domino Code Fragment

Code Name*
Mail-in agent
Date*
10/12/98
Source (or email address if you prefer)*
Jamie Magee
IP address:.3.133.144.217
Description*
Script agent shell to process newly arrived mail documents. Just plug in your own processing code.
Type*
LotusScript
Categories*
Email, Workflow
Implementation:
Modify constants
Required Client:
Server:
4.0
Limitations:
Comments:
Just plug in your own lotusscript to act on the documents.
Files/Graphics attachments (if applicable): Code:
Sub Initialize
%REM ====================================================
This agent processes newly arrived mail documents.


Normally, this agent should run "If New Mail Has Arrived" in order to run automatically on the server.
To run this agent manually, set "When should this agent run?" to "Manually From the Actions Menu"
and set "Which document(s) should it act on" to "Selected Documents".  
Then select the document(s) in a view and run this agent from the Actions menu.


21 November 1997
Jamie Magee
Martin Scott Consulting LLC
McLean, Virginia
www.MartinScott.com
Jamie.Magee@MartinScott.com


(c) copyright 1997 Martin Scott Consulting LLC

%END REM =================================================
    On Error Goto HandleError
    Dim S As New NotesSession    
    Dim DB As NotesDatabase
   
    Dim doc As NotesDocument                             '...the newly received document (usually from mail) containing the data to be imported
   
    Set db=S.currentDatabase
    Set dc = db.UnprocessedDocuments
    Set doc = dc.GetFirstDocument()
    Dim continue As Integer
    Do While Not (doc Is Nothing)          
        '...bail out if the doc is not one that we want to process...
         continue = (True)  ' put your selection criteria here in place of "True", or leave it if you want it to run on all mailed in docs
         If (continue) Then   '...doc does meet the selection criteria

               
             '...======================
             '...PUT CUSTOM CODE HERE TO ACT ON THE MAILED-IN DOC
             '...======================          



              '...some reporting
              Status$ = "Mail In Processor agent" & ": processed successfully at " &  Now & "."

               doc.Import_Status = Status$
              doc.Import_Time = Now
              doc.Import_Error = ""   '...delete any previous error message in case this agent is running again on a doc that failed once before          
              Print Status$   '...write to the Notes Log  
             
              Call S.UpdateProcessedDoc(doc)
              Call doc.save(True, True)
         End If
         Set doc = dc.GetNextDocument(doc)          
    Loop    
    Exit Sub
   
HandleError:
    ErrorMessage = AgentName & " - ERROR " & Err & " at line " & Str$(Erl) & ": " & Error$    '...get the line number, error number, and error message
    doc.Import_Error = ErrorMessage      '...write it to the doc so that it shows up in the progress tracking views
    Call doc.Save(True, True)
    Print ErrorMessage       '...print it to the Notes Log
    Exit Sub
End Sub