Error 91 on putinFolder in "before new mail arrives" agent

(this is a repost & clarification of something I posted over the weekend…)

This code is in the “before mail arrives” agent of a mailfile.

It checks to see if SpamSentinel or RDNSBL have flagged a message and moves it to the SPAM folder (this works).

I’ve added some code to copy the message to someone else’s mail file b/c the primary user is heading to Iraq for a 6 month tour.

The code correctly gets the email document, sets the subject, and copies it to the target database. BUT the putinfolder to Kstringer and ($Inbox) both error with a 91 (object var not set error) when run as a “before mail arrives” agent, but it works perfectly when I rem out the putinfolders… (the copied email shows in All Documents in the target database).

Any thoughts? TIA,

cpw…


Server 6.5.1 Win2k3

Client 6.5.1 WinXP & Win98SE


Sub Initialize

…On Error Goto errHandle…

…Dim logtxt As String

…Dim session As New notesSession

…Set session = New NotesSession

…Dim db As NotesDatabase

…Dim dbug As NotesLog

…Set db = session.CurrentDatabase…

…Dim fwDb As NotesDatabase

…Set fwDb = session.GetDatabase( db.Server, “mail\eaguilla.nsf”, False)

…Dim SPAMfolder As NotesView

…Dim email As NotesDocument

…Dim emailFw As NotesDocument

…Dim txtDNSBL As String

…Dim txtIsSpam As String

…Dim txtDNSBLcheck As Variant

…Dim SPAMfolderName As String

…Dim inboxName As String

…Dim errText As String

…Dim txtSubject As String

…Set dbug = New NotesLog(“Router log”)

…dbug.LogActions = True

…dbug.OpenAgentLog

…dbug.LogAction(“begin”)

…SPAMfolderName = “SPAM”

…inboxName = “($Inbox)”

…Set SPAMfolder = db.GetView(“SPAM”)

…Set email=session.DocumentContext

…txtDNSBL = email.~$DNSBLSite(0)

…txtIsSpam = email.IsSpam(0)

…dbug.LogAction("got here 1 " & Str$(Err) )

…'dbug.LogAction(txtDNSBL)

…If (txtDNSBL <> “”) Or (txtIsSpam <> “” )Then

…Call email.PutInFolder( SPAMfolderName, True )

…Call email.RemoveFromFolder( inboxName )

…Else

…If Not (fwDb Is Nothing) And Not(email Is Nothing) Then

…dbug.LogAction("db is set, fwdb is set, and email is set ")

…txtSubject = email.Subject(0) …

…dbug.LogAction("(FW-KS) " & txtSubject & Str$(Err) ) …

…email.Subject = "(FW-KS) " & txtSubject

…Set emailFw = email.CopyToDatabase( fwDb )

…dbug.LogAction("got here 9 " & Str$(Err) )

…Call emailFw.PutInFolder( “KStringer”, True )

…dbug.LogAction("got here 10 " & Str$(Err) )

…Call emailFw.PutInFolder( “($Inbox)”, False )

…dbug.LogAction("got here 11 " & Str$(Err) )

…Else

…dbug.LogAction("fwdb is Not set or email is not set ")

…End If

…dbug.LogAction("got here 17 " & Str$(Err) )

…End If

…dbug.LogAction("got here 18 " & Str$(Err) )

…Exit Sub

errHandle:

…Dim ErrSession As New NotesSession

…Dim Errdb As notesdatabase…

…Set Errdb = ErrSession.CurrentDatabase

…Dim errSendTo (1 To 3) As String

…Dim ErrMail As New NotesDocument(Errdb)

…errSendTo(1) = “”

…errSendTo(2) = “Craig Wiseman/CMA”

…ErrMail.SendTo = errSendTo…

…ErrMail.Subject = "Error in SPAM Agent email Agent: " & “Error #” & Str$(Err) & " - " & Error$

…Print "Error in SPAM Agent email Agent: " & “Error #” & Str$(Err) & " - " & Error$

…ErrMail.Body = “Error in: " & Errdb.Title & " | " & " true”

…Call ErrMail.Send(False)

…dbug.LogAction("got here err: " & Str$(Err) )

…'Err = 0

…Resume Next

…Exit Sub

End Sub

Subject: Try doing all the PutInFolders before you copy to another database.

Subject: Re: Try doing all the PutInFolders before you copy to another database.

I appreciate the response!

But… I want the → copied email<-- to be put into a folder in the target database.

If I putinfolder on the original email, then that won’t happen…

Any other ideas? thanks!

cpw…

Subject: Sorry, I did not read your code correctly.

Subject: Heck, → I ← have trouble doing that (i.e. reading my code correctly)

Subject: The work around…

Thanks for the responses! Since I can’t figure that one out, I moved the code to copy the emails to an “After mail has arrived” agent.

The code below works:

Sub Initialize

…Dim session As NotesSession

…Set session = New notessession

…Dim thisDb As NotesDatabase

…Set thisDb = session.currentdatabase

…Dim fwDb As NotesDatabase…

…Set fwDb = session.GetDatabase( thisDb.Server, “mail\eaguilla.nsf”, False)…

…Dim dc As Notesdocumentcollection

…Dim workDoc As Notesdocument

…Dim emailFw As NotesDocument…

…Dim txtDNSBL As String

…Dim txtIsSpam As String

…Dim txtDNSBLcheck As Variant

…Dim targetFolderName As String

…Dim inboxName As String

…Dim errText As String

…Dim txtSubject As String

…Dim txtprocessed As String

…Set dbug = New NotesLog(“Router log”)

…dbug.LogActions = True

…dbug.OpenAgentLog

…dbug.LogAction(“begin”)

…targetFolderName = “KStringer”

…inboxName = “($Inbox)”

…If fwDb Is Nothing Then dbug.LogAction(“fwdb is not set”) Else dbug.LogAction(“fwdb is set”)

…If thisDb Is Nothing Then dbug.LogAction(“thisDb is not set”) Else dbug.LogAction(“thisDb is set and thisDb.Server is” & thisDb.Server)

…Set dc = thisDb.UnprocessedDocuments…

…Set workDoc = dc.getfirstdocument

…If workDoc Is Nothing Then dbug.LogAction(“note is not set -1:” & dc.Count) Else dbug.LogAction(“note is set 1:” & dc.Count)

…While Not workDoc Is Nothing

…txtDNSBL = workDoc.~$DNSBLSite(0)

…txtIsSpam = workDoc.IsSpam(0)…

…txtprocessed = workDoc.processedCPW(0)

…If workDoc Is Nothing Then dbug.LogAction(“note is not set 2”) Else dbug.LogAction(“note is set 2”)

…If (txtDNSBL <> “”) Or (txtIsSpam <> “” ) Or (txtprocessed = “yes” )Then

…dbug.LogAction("don’t touch! " & Str$(Err) )

…Else

…If Not (fwDb Is Nothing) And Not(workDoc Is Nothing) Then

…txtSubject = workDoc.Subject(0) …

…dbug.LogAction("(FW-KS) " & txtSubject & Str$(Err) ) …

…workDoc.Subject = "(FW-KS) " & txtSubject

…Set emailFw = workDoc.CopyToDatabase( fwDb )

…dbug.LogAction(“1” & Str$(Err) ) …

…emailFw.Subject = "(FW-KS) " & txtSubject

…dbug.LogAction(“2” & Str$(Err) ) …

…Call emailFw.Save(False,False,True)

…dbug.LogAction(“3” & Str$(Err) ) …

…Call emailFw.PutInFolder( targetFolderName, True )

…'Call emailFw.Save(False,False,True)

…dbug.LogAction("got here 13 " & Str$(Err) )

…workDoc.processedCPW = “yes”

…workDoc.Subject = txtSubject

…Call workDoc.Save(False,False,True)

…Else

…dbug.LogAction("fwdb is Not set or email is not set ")

…End If

…dbug.LogAction("got here 17 " & Str$(Err) )

…End If

…txtDNSBL = “”

…txtIsSpam = “”

…txtSubject = “”

…Set emailFw = Nothing

…Set workDoc = dc.getnextdocument(workDoc)

…Wend

End Sub