(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