HOWTO: Using SpamAssassin with hMailServer V4
I found a perl script that generates reports from the spamd log. I made modifications to it so it works with the cygwin install of spamassassin. It may work ok with other versions too as long as the log files are in the same format. I also added a few options for reports. The original was found here:
http://freshmeat.net/projects/sa-stats/
and you can download mine here:
http://home.comcast.net/~carrerasg/sa-stats-mod.zip
The only thing you should have to do is modify the path in the config section so it can find your spamd log. It should run ok... but, the report for the last week and the custom report might run a little slow on a big log (I really don't know much about optimization )
EDIT: Just put up another version which corrected some errors and made the tables a little easier to read. If you had problems with the original version you might try this one. Also added an email report option. It requires the ssmtp package though (cygwin).
http://freshmeat.net/projects/sa-stats/
and you can download mine here:
http://home.comcast.net/~carrerasg/sa-stats-mod.zip
The only thing you should have to do is modify the path in the config section so it can find your spamd log. It should run ok... but, the report for the last week and the custom report might run a little slow on a big log (I really don't know much about optimization )
EDIT: Just put up another version which corrected some errors and made the tables a little easier to read. If you had problems with the original version you might try this one. Also added an email report option. It requires the ssmtp package though (cygwin).
Hi there,
I have finally installed CygWin to run SpamD on my system, and it works like a dream.
I do have problems with WinSpamC and the CygWin built SpamC.
WinSpamC buggers up most documents I have put through it - so for those who it works fine for, what system are you on? and did you build WinSpamC for yourselves or use the one distributed?
SpamC seems to replace CRs with the little square (unix CR??) and also seems to mess up the headers of the email and makes it appear with the wrong date, no subject, and no from! - Might be because I built it with CygWin, so are trying it with my 2003 windows box to build and use.
Any ideas?
John
I have finally installed CygWin to run SpamD on my system, and it works like a dream.
I do have problems with WinSpamC and the CygWin built SpamC.
WinSpamC buggers up most documents I have put through it - so for those who it works fine for, what system are you on? and did you build WinSpamC for yourselves or use the one distributed?
SpamC seems to replace CRs with the little square (unix CR??) and also seems to mess up the headers of the email and makes it appear with the wrong date, no subject, and no from! - Might be because I built it with CygWin, so are trying it with my 2003 windows box to build and use.
Any ideas?
John
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN
John
John
Strange that you wrote this today, I've been fighting with SpamC/D all day today. As I wrote before, WinSpamC has always truncated attachments on my system. Never figured out exactly why. An now recently, the cygwin version of SpamC started acting crazy... it appears that for any message over 34k, it will not rewrite the headers or mark the subject. (although I can tell from the logs that it IS in fact being scanned, and properly).john25uk wrote:I have finally installed CygWin to run SpamD on my system, and it works like a dream. I do have problems with WinSpamC and the CygWin built SpamC.
John
I'd be very interested in hearing what systems others are using also.
(I'm using WinXP SP2 with the cygwin builds)
i run spamassassin 3.0.2 on cygwin (i suggest 1.5.12 and not 1.5.13 that has some incompatibility...for example clamav stop run..), spamD as explained in our common source; winspamc is the distributed version and spamd as service (purplebear method); all work absolutily fine expecially after the introduction of user preferences functionality.
All under Windows 2003 IIS, PHP5, perl5.8, MySQL 4.1.10, and always the last bulid of HMServer;
well, i had had to remove and reinstall cuygwin many times to get the perfect stability; all problems you are encontering, i thing may depend on cygwin/spamd and never on winspamc;
i suggest to unistall cygwin and reinstall it (use 1.5.12 ..trust me) very carefully, install spamd service and get a rock solid system;
i experienced bud cygwin functionality after upgrading its installation with some other components, instead an all in one and no more action installation results fine.
procedures i installed:
Component during cygwin installation:
- All BASE packages
- under DATABASE, both the DEVEL and RUNTIME version of SleepyCat 3.1 Berkeley DB
- under DEVEL, the MAKE, GCC
- under INTERPRETERS, Perl
- under NET, the INETUTILS
- under Admin cygrunsrv for start spamd as service in cygwin
- under BASE cygwin 1.5.12-1
Once cygwin installed, under "CPAN":
- install DB_File
- install Time::HiRes
- install Net::DNS
- install HTML::Parser
- install DBI
- installation of mysql client (http://www.enstimac.fr/Perl/perl5.6.1/s ... ows/cygwin)
(last two are for activate user pref functionality)
try also to run spamd with -i HOST_IP -A IP_ALLOWED switches
and -d MAILSERVER_IP switches with WinSpamC; i feel them more solid...
All under Windows 2003 IIS, PHP5, perl5.8, MySQL 4.1.10, and always the last bulid of HMServer;
well, i had had to remove and reinstall cuygwin many times to get the perfect stability; all problems you are encontering, i thing may depend on cygwin/spamd and never on winspamc;
i suggest to unistall cygwin and reinstall it (use 1.5.12 ..trust me) very carefully, install spamd service and get a rock solid system;
i experienced bud cygwin functionality after upgrading its installation with some other components, instead an all in one and no more action installation results fine.
procedures i installed:
Component during cygwin installation:
- All BASE packages
- under DATABASE, both the DEVEL and RUNTIME version of SleepyCat 3.1 Berkeley DB
- under DEVEL, the MAKE, GCC
- under INTERPRETERS, Perl
- under NET, the INETUTILS
- under Admin cygrunsrv for start spamd as service in cygwin
- under BASE cygwin 1.5.12-1
Once cygwin installed, under "CPAN":
- install DB_File
- install Time::HiRes
- install Net::DNS
- install HTML::Parser
- install DBI
- installation of mysql client (http://www.enstimac.fr/Perl/perl5.6.1/s ... ows/cygwin)
(last two are for activate user pref functionality)
try also to run spamd with -i HOST_IP -A IP_ALLOWED switches
and -d MAILSERVER_IP switches with WinSpamC; i feel them more solid...
John... I don't know whether this will fix your problem or not but it fixed the problem I was having with winspamc truncations AND the problem with no markup with the cygwin version of spamc. I have a choice now!!john25uk wrote: WinSpamC buggers up most documents I have put through it - so for those who it works fine for, what system are you on?
John
At the very bottom of this page is a patched version of spamd... just rename your old and replace with the attachment he provides. I haven't tested long enough to see if anything new has cropped up but my initial tests show everything is good. Hope this does something for you.
http://bugzilla.spamassassin.org/show_bug.cgi?id=3917
Wasn't this one?
Code: Select all
dim filename, args
set args = wscript.arguments
if args.count = 0 then wscript.quit(99)
filename = args(0)
filename = filename & " " & args(1)
dim infile, outfile
dim fso, ts
set fso = createobject("Scripting.FileSystemObject")
if not fso.fileexists(filename) then script.quit(89)
infile = fso.getabsolutepathname(filename)
testfile = infile & ".tmp"
dim cmd, sh, rc
fso.movefile infile, testfile
cmd = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
fso.deletefile testfile
wscript.quit(7)
My OnDeliverMessage script, with learning support
Here's the OnDeliverMessage script I wrote today to hook SpamAssassin into hMail v4.
This is a first run, there some changes I know I want to make, but it's working. I've also only written 2 or 3 VBScripts in my life so I don't know the language too well, if people see places for improvement, let me know.
This builds on the examples in this thread and adds support for emailing into SpamAssassin's bayesian learning script. This uses a setup with spamd running in cygwin as a service, called by WinSpamC.
You'll need to edit the learning addresses and path to WinSpamC for your application (at least).
This is a first run, there some changes I know I want to make, but it's working. I've also only written 2 or 3 VBScripts in my life so I don't know the language too well, if people see places for improvement, let me know.
This builds on the examples in this thread and adds support for emailing into SpamAssassin's bayesian learning script. This uses a setup with spamd running in cygwin as a service, called by WinSpamC.
You'll need to edit the learning addresses and path to WinSpamC for your application (at least).
Code: Select all
Sub OnDeliverMessage(oMessage)
' set some default values
spamAddress = "report_spam@[mydomain.com]"
hamAddress = "report_ham@[mydomain.com]"
fname = oMessage.filename
Dim infile, outfile
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.fileexists(fname) then
result.Value = 0
Exit Sub
End If
infile = fso.GetAbsolutePathname(fname)
testfile = infile & ".tmp"
Dim cmd,sh,rc
fso.MoveFile infile,testfile
' LEARN IF NECESSARY
Dim oRecipients
Set oRecipients = oMessage.Recipients
For i = 0 to oRecipients.Count - 1
Dim sAddress
sAddress = oRecipients.Item(i).Address
If sAddress = spamAddress Then
LearnSpam( testfile )
result.Value = 1
End If
If sAddress = hamAddress Then
LearnHam( testfile )
result.Value = 1
End If
Next
cmd = "cmd /c D:\WinSpamC\WinSpamC.exe -t 15 -x < """ & testfile & """ > """ & infile & """"
Set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd, 0, TRUE )
'msgbox rc
' Uncomment if you want to reject spam
'If rc = 1 Then
' result.Value = 1
' Exit Sub
'End If
fso.DeleteFile testfile
Set fso = Nothing
result.Value = 0
End Sub
Sub LearnHam( f )
Dim lrnCom
lrnCmd = "cmd /c perl -T -S sa-learn --ham """ & Replace( f, "\", "\\" ) & """"
Dim lrnSh, lrnRc
Set lrnSh = CreateObject( "WScript.Shell" )
rc = lrnSh.Run( lrnCmd, 0, True )
End Sub
Sub LearnSpam( f )
Dim lrnCmd
lrnCmd = "cmd /c perl -T -S sa-learn --spam """ & Replace( f, "\", "\\" ) & """"
Dim lrnSh, lrnRc
Set lrnSh = CreateObject( "WScript.Shell" )
rc = lrnSh.Run( lrnCmd, 0, True )
End Sub
I thought that learning for forwarded messages is not a good idea? (Because the email address will be your own)
One way to do it would be to forward the un caught spam as a attachment, extract the attachment and then learn that one?
I have been meaning to do somthing similar for ages, but never got around to it! (usual story)
One way to do it would be to forward the un caught spam as a attachment, extract the attachment and then learn that one?
I have been meaning to do somthing similar for ages, but never got around to it! (usual story)
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN
John
John
Thunderbird redirect extension
Yes, it's an odd omission in Thunderbird. Most other clients have it built-in.
You need this extension:
http://mailredirect.mozdev.org/
g.
You need this extension:
http://mailredirect.mozdev.org/
g.
attachment truncated
installed spamassassin version 3.0.3 under cygwin and winspamc; attachments are truncated after passing trough spamc/spamd/spamassassin; even if i use the wspamd.bat modified... anyone?
Re: attachment truncated
I am a glutton for punishment sooo, I installed 3.0.3 But, I'm not having the problem with truncated attachments. I only tried a few though so I might be in for a surprise treat later. Anything in particular that the attachments might have in common that I can try?mirb wrote:installed spamassassin version 3.0.3 under cygwin and winspamc; attachments are truncated after passing trough spamc/spamd/spamassassin; even if i use the wspamd.bat modified... anyone?
My current setup:
Spamassassin/Spamd ver. 3.0.3
Spamc (I think I built this version from 3.0.2 but it made no difference with my previous truncation problems)
cygwin dll 1.5.17-1
EDIT: oops, I lied... kinda. It wasn't truncating the files but it wasn't actually working either. It was giving me back my original message with no mark-up.
Using SA 3.0.3 and the modified spamd (bugfix) it is now working properly. I don't know why they didn't fix the bug in 3.0.3 but apparently it will be fixed in 3.1. Anyway, copy everything from this link and paste it into your spamd file. Here's the link from bugzilla.spamassasin.org
http://bugzilla.spamassassin.org/attachment.cgi?id=2588
glenc: you talked about spamc built from spamassassin source? don't you use winspanc.exe adapted version for windows (http://sourceforge.net/projects/winspamc) instead?
When I was having troubles (like yours) about a month ago, I built spamc in an effort to fix the problem. I later found out the problem was actually with spamd. I just never changed back to winspamc. It made no real difference so I kept it.mirb wrote:glenc: you talked about spamc built from spamassassin source? don't you use winspanc.exe adapted version for windows (http://sourceforge.net/projects/winspamc) instead?
Did you try the bugfix for spamd and did it correct your problem?
Re: SPAMASSASSIN for hMailServer
i just installed the SM and its workin gr8....john25uk wrote:Hi there, just incase anyone was wondering how to - I created a directory (which is shared to my network) on my server with two subs, one called SPAM, the other HAM (EG C:\SALEARN\SPAM). They are for users to copy examples of spam that they recieve that hasn't been marked, and also for examples of regular 'proper' mail so SA can tell the difference. Then i created a batch file on a scheduler to update the database twice a day (to save logging onto the server and doing it manually) The Batch file I use can be downloaded from HERE
.
i wanna use that script of yrs....
i have loads of spam to train SA on....but the problem is from outlook or outlook express i can get only .msg files....not .eml files....
will yrscript work if i use it wid msg files??
even if i rename *.eml with *.msg can spamassassin process the .msg files??
btw tx a lot for the detailed guide....
Code: Select all
E:\spam>spamlearn
E:\spam>Rem Put SET RES_NAMESERVERS here
E:\spam>REM where SET RES_NAMESERVERS=158.152.1.58
LEARNING NEW NON-SPAM
Use of uninitialized value in concatenation (.) or string at C:/Perl/lib/File/Sp
ec/Win32.pm line 291.
Learned from 0 message(s) (0 message(s) examined).
New HAM Learned
LEARNING NEW SPAM
Use of uninitialized value in concatenation (.) or string at C:/Perl/lib/File/Sp
ec/Win32.pm line 291.
Learned from 0 message(s) (0 message(s) examined).
New SPAM Learned
E:\spam>
i put in abt 9 MB of spams/non spams....
Re: My OnDeliverMessage script, with learning support
thegregor,thegregor wrote:Here's the OnDeliverMessage script I wrote today to hook SpamAssassin into hMail v4.
Thanks for this mod, I finally got around to implementing it and I like it a lot. I made a few modifications, one was to delete the tmp files in the data directory. Other things I added are just some of my own preferences.
One thing that caused me a lot of grief when trying to implement this was the recipient part. Maybe because I have a catch-all address, but until I actually added accounts in my domain for the users "report_spam" and "report_ham", the recipient was always MY account, thus the script was aborting. After adding those accounts everything worked fine. Here's my latest version of the script:
(PS If anyone sees improvements to make here, or stupid code, please let me know... I'm a copycat coder and do a lot of things I probably shouldn't)
Code: Select all
Sub OnDeliverMessage(oMessage)
' set addresses for Spam-Ham reporting (modify these)
spamAddress = "report_spam@yourdomain.com"
hamAddress = "report_ham@yourdomain.com"
fname = oMessage.filename
Dim infile, testfile
Dim fso
Set fso = createobject("Scripting.FileSystemObject")
If Not fso.fileexists(fname) then
result.Value = 0
Exit sub
End If
infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile
'LEARN IF NECESSARY
dim oRecipients
set oRecipients = oMessage.Recipients
for i = 0 to oRecipients.Count - 1
dim sAddress
sAddress = oRecipients.Item(i).Address
If sAddress = spamAddress Then
LearnSpam( testfile )
fso.Deletefile testfile
Set fso = Nothing
result.Value = 1
End If
If sAddress = hamAddress Then
LearnHam( testfile )
fso.Deletefile testfile
Set fso = Nothing
result.Value = 1
End If
Next
'DENY CHECKS FOR MAIL FROM LOCAL DOMAIN
Dim s1, ts1, SearchString
Const ForReading = 1
Set ts1 = fso.OpenTextFile(fname, ForReading)
s1 = ts1.ReadLine
ts1.Close
'SearchString = whatever your machine inserts in the msg (modify this)
SearchString ="Received: FROM [192.168.1."
If InStr(1, s1, SearchString, 1) > 0 Then
'Comment next two lines to allow local domain spam checks
Set fso = Nothing
Exit Sub
End If
'CALL SPAMASSASSIN (modify as required)
Dim cmd, cmd1, rc, rc1, sh
cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """"
cmd1 = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
Set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
If rc = 0 Then 'Do something for HAM
ElseIf rc = 1 Then 'Do something for SPAM
'Uncomment next two lines to reject spam
' result.Value = 1
' Exit Sub
Else rc1 = sh.Run( cmd1 , 0 , TRUE) 'There was an error, call SpamAssassin directly
End If
If fso.GetFile(infile).Size = 0 Then 'Failsafe: In the event an error causes a zero byte msg
fso.CopyFile testfile, infile
End if
fso.Deletefile testfile
Set fso = Nothing
result.value = 0
End Sub
Sub LearnHam( f )
Dim lrnCmd
lrnCmd = "cmd /c perl -T -S sa-learn --ham """ & Replace( f, "", "\" ) & """"
Dim lrnSh, lrnRc
Set lrnSh = CreateObject( "WScript.Shell" )
rc = lrnSh.Run( lrnCmd, 0, True )
' MsgBox "Learning Ham, RC=" & rc,0,"Woohoo HAM!"
End Sub
Sub LearnSpam( f )
Dim lrnCmd
lrnCmd = "cmd /c perl -T -S sa-learn --spam """ & Replace( f, "", "\" ) & """"
Dim lrnSh, lrnRc
Set lrnSh = CreateObject( "WScript.Shell" )
rc = lrnSh.Run( lrnCmd, 0, True )
' MsgBox "Learning Spam, RC=" & rc,0,"Boohoo SPAM!"
End Sub
Great script.
One question with regard to the learn ham/spam process.
You are still picking up the message and parsing that for the learning process, so presumably you are relying on the message being forwarded inline? This will lose virtually all the original headers and may affect the efficiency of SpamAssassin.
Is there a way to be able to extract an attachment from a message and then process that, as that would allow users to forward the mails as attachments which would capture the full headers?
One question with regard to the learn ham/spam process.
You are still picking up the message and parsing that for the learning process, so presumably you are relying on the message being forwarded inline? This will lose virtually all the original headers and may affect the efficiency of SpamAssassin.
Is there a way to be able to extract an attachment from a message and then process that, as that would allow users to forward the mails as attachments which would capture the full headers?
Didn't notice this until now, my script is not deleting tmp files for outgoing (local) msgs. These lines:
Should be changed to this:
Code: Select all
If InStr(1, s1, SearchString, 1) > 0 Then
'Comment next two lines to allow local domain spam checks
Set fso = Nothing
Exit Sub
End If
Code: Select all
If InStr(1, s1, SearchString, 1) > 0 Then
'Comment next three lines to allow local domain spam checks
fso.Deletefile testfile
Set fso = Nothing
Exit Sub
End If
Well, those 2 pages are very interresting. I start with the begining, and I got lost after the creation of spam and ham folders...
Is there one of you nice enough to make a HOW TO as the one in the begining of the topic with all the upgrade you made?
Thanks a lot!!!!!!!!!!!!!!!!
Is there one of you nice enough to make a HOW TO as the one in the begining of the topic with all the upgrade you made?
Thanks a lot!!!!!!!!!!!!!!!!
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1
I found a solution to my problem : ASSP, just go to http://www.hmailserver.com/forum/viewtopic.php?t=1881 it is more complete than the how to http://www.hmailserver.com/documentatio ... o_use_assp and it works perfectly!
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1
Re: User Preferences instead local.cf
mirb, if you are still around, and still using phpsaadmin to set userprefs, could you let me know what code parts you had to change to make it work?mirb wrote: the only one, and pretty good, i was able to run is:
http://www.aub.dk/~misak/index.php?cat=6
changing some code parts..
Thanks,
Glen
- PeterK2003
- Normal user
- Posts: 129
- Joined: 2005-07-20 17:08
- Location: Catawissa, PA
spam assassin & clam win
Is it poosible to run clamwin and spam assassin at the same time since you need to use the external scanner box for spam assassin?
- TheAngryPenguin
- Senior user
- Posts: 341
- Joined: 2004-10-11 20:51
Sorry to chime in so late in the game -- I have only recently become interested in trying to get SA running in a Windows environment. Have any of you seen SpamAssassin for Win32 (or SpamAssassin POP3 Proxy for Win32)? I've been testing the latter with some other mail server (sorry Martin) and it seems to work rather well, albeit slow. Wouldn't something like what Eugene Pivovarov has been working on be much more easy to implement with hMS than what's been already been discussed?
Here's a google cache http://64.233.187.104/search?q=cache:E4 ... a300&hl=en
- PeterK2003
- Normal user
- Posts: 129
- Joined: 2005-07-20 17:08
- Location: Catawissa, PA
SpamAssassin for Win32
i have sucessfully used SpamAssassin for Win32 with this script:
' Sub OnClientConnect(oClient)
' End Sub
Sub OnAcceptMessage(oClient, oMessage)
Dim commandln, infile, testfile, fso
Set fso = createobject("Scripting.FileSystemObject")
fname = oMessage.filename
infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile
Set commandln = CreateObject( "WScript.Shell" )
res = commandln.Run("cmd /c spamc < " & testfile & " > " & infile & "", 0, true)
res = commandln.Run("cmd /c ", 0, true)
fso.DeleteFile testfile, true
End Sub
'Sub OnDeliverMessage(oMessage)
'End Sub
The only problem i see is that it seems to scan both outgoing and incoming mail.
I also haven't figured out how to submit spam that isn't caught so that it can learn and false positives so that it won't catch them in the future.
If any one knows that anwsers to thoe questions let me know.
' Sub OnClientConnect(oClient)
' End Sub
Sub OnAcceptMessage(oClient, oMessage)
Dim commandln, infile, testfile, fso
Set fso = createobject("Scripting.FileSystemObject")
fname = oMessage.filename
infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile
Set commandln = CreateObject( "WScript.Shell" )
res = commandln.Run("cmd /c spamc < " & testfile & " > " & infile & "", 0, true)
res = commandln.Run("cmd /c ", 0, true)
fso.DeleteFile testfile, true
End Sub
'Sub OnDeliverMessage(oMessage)
'End Sub
The only problem i see is that it seems to scan both outgoing and incoming mail.
I also haven't figured out how to submit spam that isn't caught so that it can learn and false positives so that it won't catch them in the future.
If any one knows that anwsers to thoe questions let me know.
I'll post some portions of the script which I was experimenting with. Perhaps you can do something with them to work it out. I can't guarantee they work anymore as I haven't been using them for a while. To skip checks on the local domain:
As for training... probably the best way is using Sa-learn. There are some who redirect their messages via a "bounce" but I personally think this probably negatively affects the bayes database. If you'd like to play with that here is some more code that you can tinker with. Again, not sure if it still works or not as I don't use it anymore. This also requires SpamD (which I see that you are using) This code was borrowed from Devil_Dog above and modified somewhat:
I don't think I ever got the "Forget" command to work right so it might help to worry about that portion last.
Code: Select all
'DENY CHECKS FOR MAIL FROM LOCAL DOMAIN
Dim s1, ts1, SearchString
Const ForReading = 1
Set ts1 = fso.OpenTextFile(fname, ForReading)
s1 = ts1.ReadLine
ts1.Close
'SearchString = whatever your machine inserts in the msg (modify this)
SearchString ="Received: FROM [192.168.15.1"
If InStr(1, s1, SearchString, 1) > 0 Then
'Comment next three lines to allow local domain spam checks
fso.Deletefile testfile
Set fso = Nothing
Exit Sub
End If
Code: Select all
'LEARN IF NECESSARY
spamAddress = "report_spam@example.com"
hamAddress = "report_ham@example.com"
forgetAddress = "report_forget@example.com"
dim oRecipients
set oRecipients = oMessage.Recipients
for i = 0 to oRecipients.Count - 1
dim sAddress
sAddress = oRecipients.Item(i).Address
If sAddress = spamAddress Then
Dim Spam_cmd, Spam_rc
Spam_cmd = "cmd /c spamc -L spam -u username < """ & testfile & """"
Spam_rc = sh.Run( Spam_cmd , 0 , TRUE)
'MsgBox "Spam, RC=" & Spam_rc,0,"Learned SPAM"
fso.Deletefile testfile
Set fso = Nothing
result.Value = 1 'Set to 1 to delete msg
Exit Sub
End If
If sAddress = hamAddress Then
Dim Ham_cmd, Ham_rc
Ham_cmd = "cmd /c spamc -L ham -u username < """ & testfile & """"
Ham_rc = sh.Run( Ham_cmd , 0 , TRUE)
'MsgBox "Ham, RC=" & Ham_rc,0,"Learned HAM"
fso.Deletefile testfile
Set fso = Nothing
result.Value = 1 'Set to 1 to delete msg
Exit Sub
End If
If sAddress = forgetAddress Then
Dim Forget_cmd, Forget_rc
Forget_cmd = "cmd /c spamc -L forget -u username < """ & testfile & """"
Forget_rc = sh.Run( Forget_cmd , 0 , TRUE)
'MsgBox "Forget, RC=" & Forget_rc,0,"Msg Unlearned"
fso.Deletefile testfile
Set fso = Nothing
result.Value = 1 'Set to 1 to delete msg
Exit Sub
End If
Next
For those of you using the Cygwin version of SpamAssassin, you might like to try this ClamAV plugin http://wiki.apache.org/spamassassin/ClamAVPlugin I've been using it for about a day now and it appears to work pretty well. Here's some of the advantages I think this has over the regular way of scanning:
Mail is only passed off in one operation... potentilally saving a few cpu cycles.
Instead of deleting the mails, or attachments, it inserts a "X-Spam-Status Yes" header which you can test for. With a little script work, you should be able to move those messages to a quarantine area for observation, validation or delete them or whatever.
Personally, I only did it to see if it worked, and I kinda like it.
Couple of things about installing. You of course need to be runnning Clamd to use it. You also need to install a perl module - File::Scan::ClamAV - from cpan. However, the tests run by the installation for that module fail (because it tries to connect to ClamAV through a socket vice TCPIP). But you can just force the install and it works fine.
Mail is only passed off in one operation... potentilally saving a few cpu cycles.
Instead of deleting the mails, or attachments, it inserts a "X-Spam-Status Yes" header which you can test for. With a little script work, you should be able to move those messages to a quarantine area for observation, validation or delete them or whatever.
Personally, I only did it to see if it worked, and I kinda like it.
Couple of things about installing. You of course need to be runnning Clamd to use it. You also need to install a perl module - File::Scan::ClamAV - from cpan. However, the tests run by the installation for that module fail (because it tries to connect to ClamAV through a socket vice TCPIP). But you can just force the install and it works fine.
Re: SpamAssassin for Win32
I did a little testing and due a recent change Martin made to the header structure, the "Deny Checks For Local Domain" code I posted above won't work anymore. (It was really not a good way to do that anyway) I've been testing the following code and it works well for me:PeterK2003 wrote: The only problem i see is that it seems to scan both outgoing and incoming mail.
Code: Select all
'SKIP SPAM CHECKS ON OUTGOING MAIL
Dim s1, SearchString
s1 = oMessage.HeaderValue("Received")
'SearchString = Modify this to a unique, unchanging portion of the "Received: from" header inserted by hMailserver
SearchString = "from [192.168.15.153] ([127.0.0.1]) by Yourdomain.com with hMailServer"
If InStr(1, s1, SearchString, 1) > 0 Then
' Comment out the next two lines if you don't want a header created
oMessage.HeaderValue("X-SpamCheck-Status") = "Spam checks skipped,on mail sent from local domain"
oMessage.Save()
' fso.Deletefile testfile 'uncomment this if you previously created "testfile"
Set fso = Nothing
Exit Sub
End If
Updated URLs for Step 6 of the John25uk's original post:
These are good references / tools for SA with an ActiveState Perl installation.
SpamAssassin 3.10 (Using SpamAssassin with Win32) http://64.142.36.76/howtosa310.html
SpamAssassin Configuration Tool (SaConf) http://64.142.36.76/saconf.html
These are good references / tools for SA with an ActiveState Perl installation.
SpamAssassin 3.10 (Using SpamAssassin with Win32) http://64.142.36.76/howtosa310.html
SpamAssassin Configuration Tool (SaConf) http://64.142.36.76/saconf.html
Issues Running spamd as Service with cygrunsrv
Hi!
I've been following along and have setup cygwin and spamassassin. It's all working great except I can't get it to work as a service using cygrunsrv... I'm using (as suggested by purplebear):
The command is sucessful and the service appears in the services admin. When I run it however, it says "Could not start the SpamAssassin service on Local Computer. Error 1053: The service did not respond to the start or control request in a timely fashion."
I should also mention that if from the cygwin shell i run:
everything works perfectly, spamd starts, processes requests from winspamc and logs correctly.
Can anyone offer a suggestion... please.. i've been googling for hours! LOL
Thanks muchly!
Andrew
I've been following along and have setup cygwin and spamassassin. It's all working great except I can't get it to work as a service using cygrunsrv... I'm using (as suggested by purplebear):
Code: Select all
cygrunsrv -I Spamassassin -p /usr/bin/spamd -a "-c /etc/mail/spamassassin -s /var/log/spamd.log"
I should also mention that if from the cygwin shell i run:
Code: Select all
/usr/bin/spamd -c /etc/mail/spamassassin -s /var/log/spamd.log
Can anyone offer a suggestion... please.. i've been googling for hours! LOL
Thanks muchly!
Andrew
It is probably a permission problem. With cygwin it's important when troubleshooting that you use the same user for everything. What I do is load spamd like this
and I use MY username (cygwin username). That way when I do anything from the shell it is the same as doing it with the service. This also means that when you call spamc from the eventhandler script, you should call it with a -u username also, like so
(note: --round-robin is only used with SA 3.1, and only because the default method of spawning children has problems. Roundrobin is the old style and works fine, just a little less efficient)
Code: Select all
cygrunsrv -I SpamD -p /usr/bin/spamd -a "-l -s /var/log/SpamD.log -u username --round-robin"
Code: Select all
cmd = "cmd /c spamc -E -u username < """ & testfile & """ > """ & infile & """"
I've read through all the posts in this thread and using the various code samples I have created the following code to run SA with no checking on outgoing emails. Thanks very much to the users (especially Glen) who posted the code originally .
I now want to add to this script, so that if SA finds spam then it is copied to me and not the intended recipient.
Is this possible? Any advice would be much appreciated.
Code: Select all
Sub OnDeliverMessage(oMessage)
fname = oMessage.filename
Dim infile, testfile
Dim fso
Set fso = createobject("Scripting.FileSystemObject")
If Not fso.fileexists(fname) then
result.Value = 0
Exit sub
End If
infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile
'SKIP SPAM CHECKS ON OUTGOING MAIL
Dim s1, SearchString
s1 = oMessage.HeaderValue("Received")
'SearchString = Modify this to a unique, unchanging portion of the "Received: from" header inserted by hMailserver
SearchString = "FROM [81.178."
If InStr(1, s1, SearchString, 1) > 0 Then
'Comment out the next two lines if you don't want a header created
oMessage.HeaderValue("X-SpamCheck-Status") = "Spam checks skipped,on mail sent from local domain"
oMessage.Save()
fso.Deletefile testfile 'uncomment this if you previously created "testfile"
Set fso = Nothing
Exit Sub
End If
'CALL SPAMASSASSIN (modify as required)
Dim cmd, cmd1, rc, rc1, sh
'cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """"
cmd1 = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
Set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd1 , 0 , TRUE)
If rc = 0 Then 'Do something for HAM
ElseIf rc = 1 Then 'Do something for SPAM
'Uncomment next two lines to reject spam
' result.Value = 1
' Exit Sub
Else
'rc1 = sh.Run( cmd1 , 0 , TRUE) 'There was an error, call SpamAssassin directly
End If
If fso.GetFile(infile).Size = 0 Then 'Failsafe: In the event an error causes a zero byte msg
fso.CopyFile testfile, infile
End if
fso.Deletefile testfile
Set fso = Nothing
result.value = 0
End Sub
Is this possible? Any advice would be much appreciated.
I can't think of an easy way to do it. If we had this feature: http://www.hmailserver.com/forum/viewto ... ight=event (vote for it) then it would be easier, you could just set a global rule based on the headers created by SA.
You may be able to do something with the "ElseIf rc = 1 Then 'Do something for SPAM" line, but it would get pretty complicated if you had more than a few recipients.
You may be able to do something with the "ElseIf rc = 1 Then 'Do something for SPAM" line, but it would get pretty complicated if you had more than a few recipients.
-
- New user
- Posts: 21
- Joined: 2006-01-04 22:23
I have gone through the tutorial and upon testing, received blank emails.
hmail logs show code return of 7
Any suggestions would be helpful.
hmail logs show code return of 7
Code: Select all
"DEBUG" 2556 "2006-01-04 12:49:41.343" "CustomVirusScanner::Scan()"
"DEBUG" 2556 "2006-01-04 12:49:41.531" "CustomVirusScanner::Scan() - c:\windows\system32\cscript.exe //nologo c:\sa.vbs C:\Program Files\hMailServer\Data\{ACF25BD6-9DBE-45A7-94FA-091CBAEE9239}.eml - Returned 7"
"DEBUG" 2556 "2006-01-04 12:49:41.531" "CustomVirusScanner::~Scan()"
Blank emails can occur if for some reason SA is not working (or getting called properly). I would suggest not using the CustomVirusScanner method and using a script in your eventhandlers.vbs to call spamassassin. The post above yours by dila125 is a good example for a script that you can modify to work for you. However, I just looked through it though and I noticed that two lines need to be uncommented in order to work properly.
The sa.vbs script that John25UK made was good when it was written but I think maybe some things have changed since then. (besides, eventhandlers gives you more control).
Code: Select all
'cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """"
and
'rc1 = sh.Run( cmd1 , 0 , TRUE) 'There was an error, call SpamAssassin directly
-
- New user
- Posts: 21
- Joined: 2006-01-04 22:23
Thanks. This seems better. I have tried it out but I also uncommented the following 2 lines(they were commented out):GlenC wrote:Blank emails can occur if for some reason SA is not working (or getting called properly). I would suggest not using the CustomVirusScanner method and using a script in your eventhandlers.vbs to call spamassassin. The post above yours by dila125 is a good example for a script that you can modify to work for you. However, I just looked through it though and I noticed that two lines need to be uncommented in order to work properly.The sa.vbs script that John25UK made was good when it was written but I think maybe some things have changed since then. (besides, eventhandlers gives you more control).Code: Select all
'cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """" and 'rc1 = sh.Run( cmd1 , 0 , TRUE) 'There was an error, call SpamAssassin directly
Code: Select all
'Uncomment next two lines to reject spam
result.Value = 1
Exit Sub
Code: Select all
"DEBUG" 8128 "2006-01-05 11:06:54.250" "RuleApplier::~ApplyRules"
"APPLICATION" 8128 "2006-01-05 11:06:54.281" "SMTPDeliverer - Message 7054: Message deleted. Action was taken by script subscribing to OnDeliverMessage."
-
- New user
- Posts: 21
- Joined: 2006-01-04 22:23
It appears that I am having that same issue. With those 2 lines commented, email is not being spam checked. With them uncommented, all emails are rejected.dila125 wrote:I had those lines commented because when using the spamc command, the mail was delivered without being spam checked. I therefore used the direct spam assassin command.
I admit that I have no experience with these type of scripts. Any suggestions would be helpfull.
elpresidente: Those lines are meant to delete the message. Result.Value = 1 means to discard the message. You can comment them out, or change it to Result.Value = 0 if that is not the solution you are wanting.
dila125: you are correct, the full script has two pairs of commands, but in the example you posted above you have mismatched the pairs. In effect, when it runs the line "rc = sh.run....." it will not find the command to expand to because it is commented out (i.e. "cmd = cmd /c......". In other words, cmd and rc are a pair, and cmd1 and rc1 are a pair.
Edit: ok... I see how you did it now. you modifed the rc line to use cmd1 instead of cmd. elpresidente... you will need to change that line also. It should be
I'm not sure why spamc wouldn't work for you. I haven't run it in this way in a while. Perhaps I need to try this script myself again and see if it needs tweaking.
dila125: you are correct, the full script has two pairs of commands, but in the example you posted above you have mismatched the pairs. In effect, when it runs the line "rc = sh.run....." it will not find the command to expand to because it is commented out (i.e. "cmd = cmd /c......". In other words, cmd and rc are a pair, and cmd1 and rc1 are a pair.
Edit: ok... I see how you did it now. you modifed the rc line to use cmd1 instead of cmd. elpresidente... you will need to change that line also. It should be
Code: Select all
rc = sh.Run( cmd , 0 , TRUE)
ok... I had to go back and research some things.... When you run SpamC, if you use the -E switch, it will return via the rc code a "1" if the message was spam, and a "0" if the message is ham OR if an error occurs.
If you run SpamC with the -x -E swtiches (both) it will then return a "1" for spam, a "0" for ham, and something greater than "1" for an error.
So, the IF/ELSEIF/ELSE checks the RC for 0, then 1, and if not either of those then there must have been a SpamD communication failure and it will call SpamAssassin directly.
Of course, using one or both switches results in a tradeoff... using -E alone will only return a 1 or a 0, so there is NO indication of a failure that will call spamassassin directly.
However, if you use -x -E, then you no longer have what is known as "Safe Fallback" mode (the message is returned unaltered in the case of an error) and the message NEEDS to be resubmitted and scanned by SpamAssassin directly.
I know it's a little confusing, especially because this thread is cut and pasted to death! But, personally I just use SpamC with the -E swtich now and allow it to do its Safe Fallback mode if something goes wrong. There was a time for me when SpamD wasn't reliable and I needed the extra check to make sure mail got scanned, but nowadays it is solid as a rock (knock on wood).
Hope this helps.
If you run SpamC with the -x -E swtiches (both) it will then return a "1" for spam, a "0" for ham, and something greater than "1" for an error.
So, the IF/ELSEIF/ELSE checks the RC for 0, then 1, and if not either of those then there must have been a SpamD communication failure and it will call SpamAssassin directly.
Of course, using one or both switches results in a tradeoff... using -E alone will only return a 1 or a 0, so there is NO indication of a failure that will call spamassassin directly.
However, if you use -x -E, then you no longer have what is known as "Safe Fallback" mode (the message is returned unaltered in the case of an error) and the message NEEDS to be resubmitted and scanned by SpamAssassin directly.
I know it's a little confusing, especially because this thread is cut and pasted to death! But, personally I just use SpamC with the -E swtich now and allow it to do its Safe Fallback mode if something goes wrong. There was a time for me when SpamD wasn't reliable and I needed the extra check to make sure mail got scanned, but nowadays it is solid as a rock (knock on wood).
Hope this helps.
-
- New user
- Posts: 21
- Joined: 2006-01-04 22:23
-
- New user
- Posts: 21
- Joined: 2006-01-04 22:23
I had done a little tinkering but have revertted back to this:
Which does not appear to stop the sample spam messages I send from an external account.
Code: Select all
Sub OnDeliverMessage(oMessage)
fname = oMessage.filename
Dim infile, testfile
Dim fso
Set fso = createobject("Scripting.FileSystemObject")
If Not fso.fileexists(fname) then
result.Value = 0
Exit sub
End If
infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile
'SKIP SPAM CHECKS ON OUTGOING MAIL
Dim s1, SearchString
s1 = oMessage.HeaderValue("Received")
'SearchString = Modify this to a unique, unchanging portion of the "Received: from" header inserted by hMailserver
SearchString = "FROM [81.178."
If InStr(1, s1, SearchString, 1) > 0 Then
'Comment out the next two lines if you don't want a header created
oMessage.HeaderValue("X-SpamCheck-Status") = "Spam checks skipped,on mail sent from local domain"
oMessage.Save()
fso.Deletefile testfile 'uncomment this if you previously created "testfile"
Set fso = Nothing
Exit Sub
End If
'CALL SPAMASSASSIN (modify as required)
Dim cmd, cmd1, rc, rc1, sh
cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """"
cmd1 = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
Set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
If rc = 0 Then 'Do something for HAM
ElseIf rc = 1 Then 'Do something for SPAM
'Uncomment next two lines to reject spam
' result.Value = 1
' Exit Sub
Else
rc1 = sh.Run( cmd1 , 0 , TRUE) 'There was an error, call SpamAssassin directly
End If
If fso.GetFile(infile).Size = 0 Then 'Failsafe: In the event an error causes a zero byte msg
fso.CopyFile testfile, infile
End if
fso.Deletefile testfile
Set fso = Nothing
result.value = 0
End Sub