Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Block Spam with Agent 2

Status
Not open for further replies.

WebdudeIA

Programmer
Jul 26, 2002
11
0
0
US
How do I create an agent that successfully blocks emails from outside of my company?

I've been trying to create an agent that checks for author "does not contain" and then specifying the company portion of the email address. But, outside mail still makes it through if the "TO" address contains the company name.
 
They may be a way, but I am not aware of one (Although I am not aware of a lot of notes / domino functions). I would be interested in the same thing as at the moment I have around 30 rules to place know spam in rubbish bin.

[pc]

Graham
 
There is an agent that you can create in your mail file and it works with your mail rules. Seems to work ok in R5. When you receive a piece of Spam mail, select it and run the agent. A dialog box will appear, if you choose the domain in the list it will block everything coming in from that domain, if you don't choose a domain from the list it will block just that senders email address. When I say block, it will reach your mail file but your Rules will prevent you from being bothered by it. Hope it helps.

Create an agent - Manually from Actions Menu | Selected Documents.
Paste this into the (Declarations) area:
Class SpamFilter
Private currentRulesDoc As NotesDocument
Private session As NotesSession
Private db As NotesDatabase
Private newRulesDoc As Variant
Private OrderNum As Long

Sub New
Dim rules As NotesView
Dim doc As NotesDocument
Set session = New NotesSession
Set db = session.CurrentDatabase
Set rules = db.GetView("(Rules)")
Set doc = rules.GetLastDocument
If doc Is Nothing Then
OrderNum = 0
Else
If Isnumeric(doc.OrderNum(0)) Then
OrderNum = 1
Else
OrderNum = Cint(doc.OrderNum(0))+1
End If
End If

Do Until doc Is Nothing
If doc.CurrentSpamRule(0) = "Yes" Then
Set currentRulesDoc = doc
Exit Do
End If
Set doc = rules.GetPrevDocument(doc)
Loop
If currentRulesDoc Is Nothing Then
createNewRulesDoc
End If
End Sub

Sub createNewRulesDoc
If Not currentRulesDoc Is Nothing Then
Call currentRulesDoc.save(True,False)
Call currentRulesDoc.putInFolder("Rules")
End If
Set currentRulesDoc = db.CreateDocument()
currentRulesDoc.form = "Mailrule"
currentRulesDoc.TOKEXCEPTIONLIST = ""
currentRulesDoc.TOKACTIONLIST = "3:1:"
currentRulesDoc.EXCLUDEFROMVIEW = Evaluate({@trim("A":"D")})
currentRulesDoc.PROTECTFROMARCHIVE = "1"
currentRulesDoc.ENABLE = "1"
currentRulesDoc.TYPE ="0"
currentRulesDoc.OPERATOR = "0"
currentRulesDoc.LOGIC ="1"
currentRulesDoc.IMPORTANCE = "1"
currentRulesDoc.ACTION = "3"
currentRulesDoc.IMPORTANCECOND ="1"
currentRulesDoc.ActionList = " delete the incoming message "
currentRulesDoc.CurrentSpamRule = "Yes"
currentRulesDoc.OrderNum = OrderNum
NewRulesDoc = True
OrderNum = OrderNum + 1
End Sub

Sub addNewRule(address2block As String, addresstype As String)
If Not NewRulesDoc Then
If currentRulesDoc.GetFirstItem("CONDITIONLIST").ValueLength > 10000 Then
Call createNewRulesDoc
End If
End If
If NewRulesDoc Then
Select Case addresstype
Case "Sender" :
currentRulesDoc.CONDITIONLIST = " Sender contains " & address2block
currentRulesDoc.TOKCONDITIONLIST = "1¦1¦" & address2block & "¦0"
Case "Domain" :
currentRulesDoc.CONDITIONLIST = " Internet Domain contains " & address2block
currentRulesDoc.TOKCONDITIONLIST = "B|1|" & address2block & "|0"
End Select
NewRulesDoc = False
Else
Select Case addresstype
Case "Sender" :
Call currentRulesDoc.GetFirstItem("CONDITIONLIST").AppendToTextList("OR Sender contains " & address2block)
Call currentRulesDoc.GetFirstItem("TOKCONDITIONLIST").AppendToTextList("1¦1¦" & address2block & "¦1")
Case "Domain" :
Call currentRulesDoc.GetFirstItem("CONDITIONLIST").AppendToTextList("OR Internet Domain contains " & address2block)
Call currentRulesDoc.GetFirstItem("TOKCONDITIONLIST").AppendToTextList("B|1|" & address2block & "|1")
End Select
End If
End Sub
Sub BlockDomain(domain As String)
Call addNewRule(domain, "Domain")
End Sub
Sub BlockSender(sender As String)
Call addNewRule(sender, "Sender")
End Sub
Sub delete
If NewRulesDoc = False Then
Call currentRulesDoc.save(True,False)
Call currentRulesDoc.putInFolder("Rules")
End If
End Sub
End Class

Then paste this into the Initialize area:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim col As NotesDocumentCollection
Dim doc As NotesDocument
Dim filter As New SpamFilter

Dim temp As Variant
Dim tempStr As String
Dim tempInt As Integer
Dim addresses List As Integer
Dim domains List As Variant
Dim domaincount As Long

Set db = session.CurrentDatabase
Set col = db.UnprocessedDocuments

Set doc = col.GetFirstDocument
While Not doc Is Nothing
If doc.HasItem("SMTPOriginator") Then
tempStr = Trim$(doc.SMTPOriginator(0))
If tempStr <> &quot;&quot; Then
temp = Evaluate({@RightBack(&quot;} & tempStr & {&quot;;&quot;@&quot;)})
Call Addaddress(domains(temp(0)), tempStr)
End If
End If
Set doc = col.GetNextDocument(doc)
Wend
Dim domainarray() As String
Forall domain In domains
Redim Preserve domainarray(0 To domaincount)
domainarray(domaincount) = Listtag(domain)
domaincount = domaincount +1
End Forall
Dim workspace As New NotesUIWorkspace
Dim askme As Variant
askme = workspace.Prompt(PROMPT_OKCANCELLISTMULT, &quot;Domain Blocking&quot;, &quot;Here is the list of domain's of the mail you ran this agent on. Please select any domain(s) that you do not want to get mail from&quot;, Nothing, domainarray)
If Isarray(askme) Then
Forall domain In askme
Call filter.BlockDomain(Cstr(domain))
Erase domains(domain)
End Forall
End If
Forall domain In domains
Forall sender In domain
Call filter.BlockSender(Cstr(sender))
End Forall
End Forall
Delete filter
Call col.removeAll(True)
End Sub
Sub AddAddress(alist As Variant, address As String)
If Not Islist(alist) Then
Dim temp List As String
alist = temp
End If
alist(address) = address
End Sub
 
Is it not possible to do this through Domino Administrator? I believe (though I don't have the program with me now) its possible to set a rule on the server, through the Messaging configuration document or the server document, which will prevent external mail from being delivered to a specific user.

Only an idea...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top