Wednesday, May 17, 2006

Reporting Spam to SpamCop from Lotus Notes

Here is a very simple agent to report a select email or emails to spamcop's quick reporting service. You will need a spamcop account and access to quick reporting.

It uses a new r6 feature of lotusscript to get the received header information so that spamcop will know exactly where the email came from at each hop. This is important as they use this for their black lists so that the correct servers are blocked while the innocent receiving servers are not.

It is also important to list your allowed hosts with spamcop so that if it routes through some of your servers then these will not be treated at open relays.

Sub Initialize
Dim s As New notessession
Dim dc As NotesDocumentCollection
Dim db As notesdatabase
Dim doc As notesdocument

Set db = s.CurrentDatabase
Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument


While Not(doc Is Nothing)

Dim text As String
text = ""
Forall t In doc.GetReceivedItemText
text = text + "Received: " + t + Chr(10)
End Forall
Forall it In doc.Items
If it.name <> "Received" Then
text = text + it.name + ": " + it.text + Chr (10)
End If
End Forall

Dim mail As notesdocument
Set mail = db.CreateDocument

mail.form = "memo"
mail.subject = "Spam to report"
mail.body = text

Call mail.Send(False, "spam@uce.gov")
Call mail.Send(False, "quick.[yoursecretkeyhere]@spam.spamcop.net")

'You can then save or just delete it here
doc.RemoveFromFolder("($junkmail)")
Call doc.Save(True, False)

Set doc = dc.GetNextDocument(doc)
Wend
End Sub

Like this article? Digg it!

4 comments:

Anonymous said...

Hi Ian, very good idea and a great agent. But can u pls update the code to avoid the repeating received headers in the normal text items. Thanks and best regards, Stefan

None said...

Code updated - good catch and thanks for the code tip!

None said...

Here is the body if you want to send the email as an attachment instead of in the body.

fileNum% = Freefile()
Open "c:\report.txt" For Output As fileNum%

Dim text As String
text = ""
Forall t In doc.GetReceivedItemText
text = text + "Received: " + t + Chr(10)
End Forall
Forall it In doc.Items
If it.name <> "Received" Then
text = text + it.name + ": " + it.text + Chr (10)
End If
End Forall

Dim mail As notesdocument
Set mail = db.CreateDocument

mail.form = "memo"
mail.subject = "Spam to report"
Write #fileNum%, text
Close fileNum%

Set rtitem = New NotesRichTextItem( mail, "Body" )
Set object = rtitem.EmbedObject _
( EMBED_ATTACHMENT, "", "c:\report.txt")

Call mail.Send(False, "[address here]")

Set doc = dc.GetNextDocument(doc)

Anonymous said...

I have also now used this so that email sent to spamtrap@projectlounge.com or spambait@projectlounge.com get automatically queued and reported to spamcop.