HOWTO: Using SpamAssassin with hMailServer V4

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-06 17:48

Are you not getting any markup in the headers of the emails you sent yourself? Like X-Spam-Level?

Is SpamD running? If it is you should see about 5 instances of perl.exe running in your task manager.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-06 21:35

GlenC wrote:Are you not getting any markup in the headers of the emails you sent yourself? Like X-Spam-Level?

Is SpamD running? If it is you should see about 5 instances of perl.exe running in your task manager.
There's the problem. I did not get that installed properly I guess. What is the best way to do that? Is it in the tutorial at the beginning of the thread and if so, is it still applicable?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-06 22:24

I scanned through the tutorial and didn't see it. You should be able to test it by just running spamd in a dos box for now. ( spamd -D -u username ) When you know what command line options work best for you then you can probably install it as a service with Srvany. It's been a while since I ran with activestate so my memory is failing me as to any other things you might need to do.

If all else fails you should still be able to run the raw SpamAssassin, but your script will need to be modified in order to do so.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-06 22:39

GlenC wrote:I scanned through the tutorial and didn't see it. You should be able to test it by just running spamd in a dos box for now. ( spamd -D -u username ) When you know what command line options work best for you then you can probably install it as a service with Srvany. It's been a while since I ran with activestate so my memory is failing me as to any other things you might need to do.

If all else fails you should still be able to run the raw SpamAssassin, but your script will need to be modified in order to do so.
I must've done something wrong along the way. spamd and spamc both return "is not recognized as an internal or external command". spamassassin works from the dos prompt. I guess I assumed that spamc/d was created during the nmake step of the tutorial. I apologize for that.

I want to use spamd/spamc. What's my next step?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-06 23:06

crap...

I feel like I have wasted your time. You just made me remember that SpamD will NOT run with activestate perl without some pretty heavy modification. And you need to use a specially built version of SpamC too.

I am REALLY sorry!

If you want to try anyway... here is the link for the mods that had to be made for SpamAssassin version 3.0. I have no idea how this will work with 3.1
http://wiki.apache.org/spamassassin/SpamdOnWindows

Here is the link for the windows version of SpamC:
http://sourceforge.net/projects/winspamc

I had run it this way for a while but had forgotten what all was involved to make it work.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-06 23:21

GlenC wrote:crap...

I feel like I have wasted your time. You just made me remember that SpamD will NOT run with activestate perl without some pretty heavy modification. And you need to use a specially built version of SpamC too.

I am REALLY sorry!

If you want to try anyway... here is the link for the mods that had to be made for SpamAssassin version 3.0. I have no idea how this will work with 3.1
http://wiki.apache.org/spamassassin/SpamdOnWindows

Here is the link for the windows version of SpamC:
http://sourceforge.net/projects/winspamc

I had run it this way for a while but had forgotten what all was involved to make it work.
No need to apologize. I appreciate all the help you are giving me.

Could I switch to cygwin? Is this practical? I have no other reason to have activestate on the server and only installed it for SA. I don't mind making modifications, etc. I'll do whatever it takes. I would like to have SA-learn running well, ultimately, I think.

Thanks again. I've worked in computer support for about 5 years. i know how these things go (my boss is not as patient but oh well). I have never dealt with perl and have installed SA once on a web server I lease (pretty straight forward in linux).

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-06 23:33

Yes you can, and actually it will be better because with cygwin you get the full functionality of spamd.

The cygwin install is a little more tedious, but once it is working, it works well (for me at least)

Here is the link to the How-To http://www.hmailserver.com/forum/viewtopic.php?t=3144

It appears that at least a few people have had good success following those instructions.

As for activestate, you should be able to just uninstall it. Just make sure that you remove the reference to c:\perl\bin in your path, I doubt the uninstall will do that for you.

One other thing that the How-to doesn't mention, but that I think probably needs to be fixed in the How-to... don't install it as the user "Administrator" I think spamd will refuse to run as that user.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-06 23:43

GlenC wrote:Yes you can, and actually it will be better because with cygwin you get the full functionality of spamd.

The cygwin install is a little more tedious, but once it is working, it works well (for me at least)

Here is the link to the How-To http://www.hmailserver.com/forum/viewtopic.php?t=3144

It appears that at least a few people have had good success following those instructions.

As for activestate, you should be able to just uninstall it. Just make sure that you remove the reference to c:\perl\bin in your path, I doubt the uninstall will do that for you.

One other thing that the How-to doesn't mention, but that I think probably needs to be fixed in the How-to... don't install it as the user "Administrator" I think spamd will refuse to run as that user.
Excellent. I'm excited to make the change. Full functionality is key. 8)

So do not install cygwin when logged in as administrator or does it ask what user to run under?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-07 00:00

You can install cygwin for all users. But it won't ask what user to run it under. I don't know for sure it is a problem, but if you read the thread you will see that it appears that one person might have an issue trying to run it that way. To be safe, I would just avoid that and install it under a different windows user. On my machine, I installed it while logged in as GlenC, and then when setting up the scripts and services I used the "-u GlenC" option for spamd, spamc and sa-learn. You have some experience with Linux so you understand how the permissions and users and groups can get to be a PIA.

Edit: Note that I meant "Administrator" and not a "Member of the Administrator Group" which won't pose that problem.

webavant
Normal user
Normal user
Posts: 103
Joined: 2005-12-22 04:10
Contact:

Post by webavant » 2006-01-11 06:38

Why hasn't this: http://www.hmailserver.com/forum/viewto ... =9101#9101 been turned into a how to?

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-11 17:11

I installed cygwin and have it up and running for now. I would like to add salearn, etc to script but that can wait. Thanks to all that helped. It's much appreciated. I will have no qualms about recommending hMailServer to others.

webavant
Normal user
Normal user
Posts: 103
Joined: 2005-12-22 04:10
Contact:

Post by webavant » 2006-01-12 05:23

I am running spamd, spamc and sa-learn in Cygwin. Am I going to run into any issues following this: http://www.hmailserver.com/forum/viewto ... =9101#9101 process to get user-level configuration?

webavant
Normal user
Normal user
Posts: 103
Joined: 2005-12-22 04:10
Contact:

Post by webavant » 2006-01-12 08:46

To stay on the current subject that this thread seems to have taken on, I tried to run SpamD in Cygwin and had some problems, as observed in the other thread. I gave up for a couple days and installed Active State Perl and ASSP, then came back to Cygwin because I was disappointed with ASSP and new that SpamD runs so much better in Cygwin than in Active State Perl.

I am currently running both Active State Perl and Cygwin fine. I imagine I may have to make sure that there are no conflicting instances of programs using the same filenames in both c:\perl\bin and c:\cygwin\bin sometime down the road if I decide to utilize any of them. I also had to disable the ASSP service in the MMC, but I didn't uninstall ASSP because you never know. I imagine if you have installed SA in both Cygwin and ActiveState Perl you will have to disable some services, rename some files or uninstall one or the other completely.

webavant
Normal user
Normal user
Posts: 103
Joined: 2005-12-22 04:10
Contact:

Post by webavant » 2006-01-12 10:26

I am running hMailServer and SpamAssassin on Cygwin. I want to set it up so that any detected spam be moved to an IMAP folder for that account. I want to also set up a webmail app, any app, that will tie in to SpamAssassin as much as possible. Then allowing users to change SA config prefs all within the same webmail app would also be a plus. Anyone know how it is done?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-12 15:14

webavant wrote:II want to also set up a webmail app, any app, that will tie in to SpamAssassin as much as possible. Then allowing users to change SA config prefs all within the same webmail app would also be a plus. Anyone know how it is done?
You can take a look here, there are some SM plugins and other options for configuring SA prefs. I would recommend going the SQL route so you don't end up with a bunch of user directories in your cygwin directory though. http://wiki.apache.org/spamassassin/WebUserInterfaces

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-12 15:30

webavant wrote:I am running spamd, spamc and sa-learn in Cygwin. Am I going to run into any issues following this: http://www.hmailserver.com/forum/viewto ... =9101#9101 process to get user-level configuration?
You will need to parse the recipients list to get the users and run spamc for each recipient. I experimented with this a while back and was using something along the lines of this... you will need to clean this up to make it work properly I think:

Code: Select all

dim cmd, rc, sh, infile, testfile, recip_addr, recip_name
infile = fso.getabsolutepathname(file_name)
testfile = infile & ".tmp"
fso.copyFile infile, testfile

'ID recipients in order to use SpamD user_prefs
for i = 0 to oMessage.Recipients.Count - 1

'Separates the user name from the domain, place in recip_name(0)
'you need to modify this if your SA setup uses user@domain.com names.
recip_addr = oMessage.Recipients(i).Address
if oMessage.Recipients.Item(i).IsLocalUser then
	recip_name = Split(recip_addr, "@",-1,0)
'call spamc for each recipient
	cmd = "cmd /c spamc -E -s 512000 -u """ & recip_name(0) & """ < """ & testfile & """ > """ & infile & """"
	set sh = CreateObject("WScript.Shell")
	rc = sh.Run( cmd , 0 , TRUE)
	If rc = 0 Then			'Normal operation HAM
	'	Msgbox "Result code 0", 0, "Msg"
		Elseif rc = 1 Then	'Normal operation SPAM
	'	Msgbox "Result code 1", 0,"Msg"
	End If
end if
next 

Aaron
New user
New user
Posts: 4
Joined: 2005-12-11 05:26
Location: California
Contact:

Blank emails...?

Post by Aaron » 2006-01-16 13:18

Do you know why I keep getting blank email messages? Everything else works great. SpamAssassin has been installed properly and tested to work manually. But when I plug it into hMailServer, using either the scripting method or the External Virus Scanner, all I ever get is a blank email with NOTHING in it. No headers, no body, no nothing.

I've spent several hours trying to figure this out and I'm out of ideas.

Thanks!

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-16 16:03

Are you using spamd? And if so, is it running? That is the common mistake. Also, is perl in your path?

If those don't fix it, post the relavent portion of your script.

SoundOfEmotion
New user
New user
Posts: 4
Joined: 2006-01-27 09:55
Contact:

Post by SoundOfEmotion » 2006-01-29 08:49

"If it is not working and you are getting only blank emails in your inbox, check you have R64"
What do you mean, R64? Revision .64 of SpamAssassin? of hMailServer?... This line makes no sense to me...

I've installed SpamAssasin, i have made spamc.exe, and i've got the vbscript set up and configured to run as an External Antivirus, but all i get are BLANK EMAILS... No subject, no sender, no body... All blank.

Help!

SoundOfEmotion
New user
New user
Posts: 4
Joined: 2006-01-27 09:55
Contact:

Post by SoundOfEmotion » 2006-01-29 10:09

Ok, upon closer inspection of this How To, i realize that what is meant to be done is modifying the C:\Program Files\hMailServer\Events\EventHandlers.vbs file, and uncommenting, and creating the Sub onDeliverMessage(oMessage) sub to have a value that does all the spam-checking...

But for the average reader it is extremely frustrating, and difficult to understand.

Could we please find an agreeable onDeliverMessage sub and re-post it as clear and precise as possible. And what would be even better would be to "Edit" the first post, so that the next user doesn't come up and start from square one, and have problems, then try cygwin, then realize they need to do a bunch of other crap, and then finally come to realize that they just need a few files and need to modify their EventHandlers vbscript...

That's just my opinion...

And i still cannot get the EventHandlers to do anything to spam. I've tried all of the vbscripts, but to no avail... Please help!

Aaron
New user
New user
Posts: 4
Joined: 2005-12-11 05:26
Location: California
Contact:

Blank emails

Post by Aaron » 2006-01-29 11:46

I still haven't gotten SpamAssassin to work. At the moment, it's not being utilized because all I get is blank emails.

I have successfully tested SpamAssassin by passing email into it manually and it spits back a modified email with the headers updated and such. Perl is in my command path. All seems well with the world.

The problem lies in the connection from hMailServer to SpamAssassin. I've tried many different variations... using both the Virus Scanner to call SpamAssassin and the EventHandlers.vbs. Neither makes any difference. I still get blank emails.

I've added debug output to figure out what's going on. All I can figure out is that SpamAssassin is NOT being called by hMailServer. The script blows right past the call to SpamAssassin and somehow ends up with a blank email.

I have confirmed that the script IS creating the email file and the temporary email file. I have even taken the email file in the directory where it's created and used the exact VBS code from my script to call SpamAssassin the same way (but doing it manually with a custom .VBS file) and it works fine: SpamAssassin is launched and a couple seconds later, it rewrites the email file with the spam headers. However, it fails when hMailServer tries to do it. There is no error whatsoever. I just get blank emails.

The only significant difference I can figure out between my setup and everyone else's is that everyone else seems to be using CygWin. Before I continue installing more and more stuff on my server, I was hoping I could get it to work without CygWin. Then, once that was working, I figured I would see how the performance was. Only then would I go the CygWin route... if the performance needed a boost. But maybe most others aren't seeing my problem because they're all blowing right past my basic setup and they're going straight to CygWin which might inadvertently fix whatever my problem is?? I don't know.

Here is the OnDeliverMessage() code I currently use. Keep in mind, I have used at least a dozen variations of this code, much of it taken from this form, and the result is always the same.

Code: Select all

	fname = oMessage.filename 
	Dim infile, testfile, sh 
	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 
	Set sh = CreateObject("WScript.Shell") 
	
	'CALL SPAMASSASSIN 
	Dim cmd, rc 
	cmd = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """" 
	rc = sh.Run( cmd , 0 , TRUE) 
	result.Value = 0 
	fso.Deletefile testfile 
	Set fso = Nothing 
By the way, I have to second SoundOfEmotion's comment that the original post should be edited. I was also (and still am) very confused about the "R64" reference. I still don't know what that means! But from the post, it sounds crucial.

Thanks for your help, guys! I really appreciate it!

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-29 14:48

R64 refers to the minimum requirement for hmail (hMailServer 3.4 Build 64)

The problem is obviously here:

Code: Select all

cmd = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """" 
The only way you are going to get blank emails is if this line is executed AND spamassassin is not returning the marked up message to "infile"

You can tell the line is being executed because that is the only way "infile" will change... nothing else writes to "infile"

Your command to call spamassassin looks ok, so that really only leaves two things in my mind. Either the script can't find perl, or perl can't find spamassassin.

Since you say perl is in your path, that leaves spamassassin. What directory did the spamassassin executeable get installed to and is THAT in your path?

That's about all I can guess... your script looks ok to me otherwise.

SoundofEmotion: Your problem is similar, except you need to 1. Ensure spamd is running and 2. Ensure perl and spamc are in your path.

Also note that spamd won't run with activestate perl... unless you make some modifications to the spamd file. I believe there is a link to that somewhere in this thread.

hmag
New user
New user
Posts: 21
Joined: 2006-01-19 06:43
Location: Australia
Contact:

Post by hmag » 2006-02-10 03:39

john25uk wrote:If you want to have hmail delete the spam for you, open the vbs file and change the wscript.quit(7) to wscript.quit(rc)

and
add the -e to the cmd string ie:
cmd = "cmd /c perl -S -T -w spamassassin -e < """ & testfile & """ > """ & infile & """"

and set the return code in hMailServer Admin to 5

then it will delete everything that spamassassin thinks is spam.

Though i would get everything marked as spam put into a seperate mailbox instead, so you can check it first before deleting it as you won't know if its really ham

John
Hi again,
I followed the entire thread through here - Spam Assassin 3.1 is running fine, hMail is processing mail & Spamassassin is marking mail up, but I cannot get mail to be deleted using John25UK's suggested method above. Can anyone assist with this please?

I changed the line mentioned above in sa.vbs, saved, rebooted the entire machine in case something was not taking immediate effect. Any assistance would be greatly appreciated. - Terry
Bye for now, Terry

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-02-10 23:04

It has been so long since I messed with that script from John25UK. The first thing you should check I suppose is to ensure you are using the "-e" switch on your call to spamassassin.

Make sure you changed the last line in the .vbs file from (7) to (rc)

Next, look in your logs (you may have to turn on debug logging and application logging) and make sure that "5" is the value being returned. The SpamAssassin docs say that using the "-e" switch will cause spamassassin to return a value > 0. I don't know where the "5" value came from. So look and see what the log says it is returning and try using that value.

hmag
New user
New user
Posts: 21
Joined: 2006-01-19 06:43
Location: Australia
Contact:

Post by hmag » 2006-02-11 10:56

Hi again,
Many thanks Glen, I will check that out. The script was definitely modified so that the last line is indeed changed to 'rc' instead of 7. I will have to check what values the server is returning.

The 0 is perhaps what the problem is. It's a shame that the web admin doesn't assist in changing or viewing the logs at this stage, because I will have to visit the client's office agan for this.
Bye for now, Terry

hmag
New user
New user
Posts: 21
Joined: 2006-01-19 06:43
Location: Australia
Contact:

Post by hmag » 2006-02-13 10:48

Hi again,
GlenC - the problem was very simply the fact that all changes had been made, including the last line to rc, but the changes had not been saved (where did I leave my head by the way?). After checking it had been saved now, everything is working as expected.

Just for everyone's information, SpamAssassin by default marks any value over 5 as 'spam=yes', so that's where the value comes from & that's what the script returns if it is spam. If the value is between 0-5, then it is not classed as spam & is passed through without issue. This is exactly the way SpamAssassin runs on *nix servers I administrate.
Bye for now, Terry

trax
New user
New user
Posts: 2
Joined: 2006-07-25 09:48
Location: France

Post by trax » 2006-08-01 15:28

Hi,

To use SA 3.1.3 with option "-e", you need modify spamassassin script in C:\Perl\Bin.
Replace the line : eval { $exitvalue ||= $iter->run(@targets); };
by the line : $iter->run(@targets);

that's return 5 for a spam and 0 for a non-spam

fingers
New user
New user
Posts: 7
Joined: 2005-08-22 14:33

Query on SA and hM

Post by fingers » 2006-08-29 14:34

Anyone attempted to use this Win32 non-cygwin/non-perl version of Spamassassin? http://physics.ucsd.edu/~epivovar/anti-spam.htm
... SpamAssassin for Windows (Win32), a native Windows build of spamassassin and spamd/spamc command-line tools. (Especially useful on mail servers.)...

weetabix
Normal user
Normal user
Posts: 36
Joined: 2005-07-16 01:46

Re: Query on SA and hM

Post by weetabix » 2006-09-19 07:09

fingers wrote:Anyone attempted to use this Win32 non-cygwin/non-perl version of Spamassassin? http://physics.ucsd.edu/~epivovar/anti-spam.htm
... SpamAssassin for Windows (Win32), a native Windows build of spamassassin and spamd/spamc command-line tools. (Especially useful on mail servers.)...
I am trying to, i get everything working except having spamd running as a service.

it works perfect when i just start it by doubleclicking spamd.exe in the catalogue, but when i try to set it up as a service with srvany i cant get it to work.

anyone have got it working and can make a brief walkthrough?

EDIT: found the answer by googling a bit:
pop3proxy wrote:Hi, Yann! I am the guy who maintains spamassassin for windows. Found your post accidentally by googling...

I believe that the root of the problem is in the fact that my build of spamd finds all other files (in particular, the rules) relative to the current folder, unless you install it in the folder \usr. You should probably create a file spamd.bat and put two lines there

cd {full path to SpamAssassin for Win32 folder}
spamd.exe

Then run this spamd.bat as a service. I have updated the Readme file so that now it explains that.
Last edited by weetabix on 2006-09-19 07:23, edited 1 time in total.

fingers
New user
New user
Posts: 7
Joined: 2005-08-22 14:33

Re: Query on SA and hM

Post by fingers » 2006-09-19 07:19

weetabix wrote:
fingers wrote:Anyone attempted to use this Win32 non-cygwin/non-perl version of Spamassassin? http://physics.ucsd.edu/~epivovar/anti-spam.htm
... SpamAssassin for Windows (Win32), a native Windows build of spamassassin and spamd/spamc command-line tools. (Especially useful on mail servers.)...
I am trying to, i get everything working except having spamd running as a service.

it works perfect when i just start it by doubleclicking spamd.exe in the catalogue, but when i try to set it up as a service with srvany i cant get it to work.

anyone have got it working and can make a brief walkthrough?



I've been Using - XYNTService.exe and it's Working Greate Have Had it running for 2+weeks and no mem leaks etc
uses about 48mb

Code: Select all


------Start install.bat------
@ECHO OFF
ECHO ----------------------------------
ECHO Install SpamD as a Windows Service
ECHO ----------------------------------
ECHO.
ECHO.
ECHO Make Sure you have edited 
ECHO     \SA\XYNTService.ini
ECHO.
ECHO Reflecting your Drive\Folder Location of SA
ECHO.
ECHO And....
ECHO.
ECHO spamd.exe -i(Listening Network interface) 127.0.0.1 -A(Only Accept Connections From) 127.0.0.1
ECHO.
ECHO.
pause
XYNTService.exe -i
ECHO Edit the Service Properties Before Continuing...
ECHO.
ECHO ie use a user and Password "that will be allowed to logon as a Service"
ECHO Note: Make Sure it is An Existing User
ECHO.
ECHO Then, and Only Then, Continue to Run this Batch File to Start the SpamD_SVC
ECHO.
pause
XYNTService -r SpamD_SVC
------End install.bat------

Code: Select all

XYNTService.ini
[Settings]
ServiceName = SpamD_SVC
CheckProcessSeconds = 30
[Process0]
CommandLine = C:\SA315\spamd.exe -i 127.0.0.1 -A 127.0.0.1 --syslog="C:\logs\spamd.log"
WorkingDir = C:\SA315\
UserInterface = No
Restart = Yes
Don't forget to edit the local.cf

I use.....
required_score 6.3
bayes_auto_learn 1
use_bayes 1
ok_locales all
report_safe 0
rewrite_header Subject [**ASSASSIN**]
dns_available test: [localdomain.tdl dns server]
bayes_path c:/SA315/etc/spamassassin/bayes
bayes_auto_learn_threshold_nonspam 0.05
trusted_networks 127.0.0.1

stylus
New user
New user
Posts: 20
Joined: 2006-02-10 03:17

Use Eventhandler.vbs instead of external virus scanner?

Post by stylus » 2006-09-21 04:35

Hello,

Using this howto: I was able to get the basic spam assassin up and filtering

I continued reading down the tread and found some code for the eventhandler.vbs instead of the external virus scanner setup but it didn't seem that the author was too confident in the code at the time.

Is there some code that is accepted as good and stable for a fairly basic install of SA, I haven't tackled spamC/spamD and I still have a lot of sorting to do before I can have bayes working well.

Thanks

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-09-21 05:06

If you are referring to the code in this thread: http://www.hmailserver.com/forum/viewto ... 2643#22643 it looks like it will work ok. Just make sure that perl is in your path.

Kingo
New user
New user
Posts: 8
Joined: 2006-09-04 07:02
Location: Brisbane, Australia
Contact:

Post by Kingo » 2006-09-21 07:00

Stylus, I can vouch for GlenC on that one. I've been using it for about a month now without a single problem.

h4ns
New user
New user
Posts: 13
Joined: 2006-03-16 20:21
Location: Belgium

Post by h4ns » 2006-10-18 10:59

That does confirm my suspicion that running SA in the OnDeliverMessage makes it impossible to set a Global Rule for moving spam to the right folder...?

marvista
New user
New user
Posts: 18
Joined: 2006-03-20 01:41

Post by marvista » 2006-11-05 07:25

Revisting an issue with OnDeliverMessage.....

Since OnDeliverMessage checks both incoming and outgoing messages, Martin had made a suggestion to check the From header before running the spam check. However, I'm finding a lot of spam with bogus headers saying they are from the person they are trying to send to.

Is there - could there be - a message property that OnDeliverMessage could check which is which IP Range the message is coming from? That would be checking the data I am interested in, rather than trying to find a surrogate for it.

MV

bazporter
Normal user
Normal user
Posts: 98
Joined: 2005-06-03 16:14

Post by bazporter » 2006-11-05 10:37

If you do a check of the received header (first line of the mail) to decide whether it is a local or externally originated mail I have found that you need to look for two possible striings:

Code: Select all

' Received header RegEx strings For local mail
' cRecHdr1 will match any mail sent from a local source other than hMailServer
const cRecHdr1 = "(Received\: from ((\[192\.168\.1\.[0-9].*\])|hostname.|hostname) \(.(192\.168\.1\.[0-9].*|127\.0\.0\.1).\))|(Received\: from domain\.tld \(\[127\.0\.0\.1\]\))"
' cRecHdr2 will match on warning mails generated by hMailServer
const cRecHdr2 = "(Message-ID: <.*@host\.domain\.tld>)"
If it matches either of these it's local so doesn't need to get checked by SA.
HTH
--
Regards
Barry

schworak
Normal user
Normal user
Posts: 30
Joined: 2006-05-06 18:09

Post by schworak » 2006-11-05 23:30

I wish SA was faster because I would love to do the test while the remote server is connected and reject it at that level. But it is way too slow!

Thanks for all the great info in this area.

I hope the future versions of hMail get better SA integration too.

Shiloh
Normal user
Normal user
Posts: 163
Joined: 2006-04-14 00:00

Post by Shiloh » 2006-11-08 23:49

I posted an article about how to integrate SpamAssassin into hMailServer without launching any external processes. This is an extremely scalable solution for busy email servers. Here is a link to the article:
http://www.howiblockspam.com/index.php? ... icle&sid=2

mthosting
Normal user
Normal user
Posts: 38
Joined: 2006-06-21 01:51
Location: NYC
Contact:

Post by mthosting » 2006-11-21 22:28

I was messing with this com object, does it support sending a username?

thanks
sc

remyb
New user
New user
Posts: 1
Joined: 2006-11-23 09:17

way to check and delete spam

Post by remyb » 2006-11-23 09:21

hello everyone :-)

many thanls for all your help and all the tips supplied in this post.... i actually installed spamassassin, making it work first by the mean of the external virus scanner and the by the scripts.

my question : with the external virus scanner i could delete the mail easily, i made a rule in hmailserver to delete each taged mail.

with the scripts it is not possible if i use the ondelivermessage, the rules are not applied. so i had to put SA in the onacceptmessage, wich cause delays...

what could i do as a better solution to have the spam directly deleted?

EDIT: another problem is that i had to desactivate spamassassin check because my computer was freezing each time a large e-mail was checked....... any way to handle that ? help would be much appreciated.

Shiloh
Normal user
Normal user
Posts: 163
Joined: 2006-04-14 00:00

Post by Shiloh » 2006-11-29 19:19

prolifix: No, my COM object does not support sending a username. I assume you are asking about the username field because you want to do per user rules in SA. I do not set up per user rules in SpamAssassin.

I do my spam thresholds on a per user basis on the email server side, because it is much easier to manage. In our environment, we have a load balanced cluster of SA boxes. It is not really practical to maintain per user rules on each SA box and we do not want the SA boxes to need to share a MySQL instance because that would be a single pont of failure.

The most useful per user rule is the SA threshold. And that is implemented in the email server VBS script, so each user can have his/her own custom threshold.

Shiloh
Normal user
Normal user
Posts: 163
Joined: 2006-04-14 00:00

Post by Shiloh » 2006-11-29 19:22

remyb: Are you trying to run spamassassin on the same box as hMail? I've tried that in the past but the performance is terrible that way. You really need to set up SpamD on a separate box and then connect to it from the hMail box using TCP. This will relieve the strain on your email server. If you need even more performance, set up a load balanced cluster of SpamD boxes. When we retire old web server, we format the old boxes and set them up in our SpamD cluster. It is an excellent way to recycle old hardware.

Shiloh
Normal user
Normal user
Posts: 163
Joined: 2006-04-14 00:00

Post by Shiloh » 2006-11-29 19:27

schworak: I created a poll regarding how I think SA should be integrated into hMail. I think the SpamC section of the code should be integrated but NOT the main SpamAssassin or SpamD section of the code. With the SpamC code (which is extremely tiny and very effecient) integrated into hMail, it would be very easy for people to connect to SpamD instances.

Here is a link in case you have not voted on it yet:
http://www.hmailserver.com/forum/viewtopic.php?t=4268

mthosting
Normal user
Normal user
Posts: 38
Joined: 2006-06-21 01:51
Location: NYC
Contact:

Per User Spam Folder

Post by mthosting » 2006-12-04 04:47

Since OnDeliver occurs after the global rules this script puts a rule for each user account to put spamassasin spam into "Junk Mail" imap folder. The script enforces the rules to make sure it exists.

Code: Select all

'Stephen Cattaneo
'MT Hosting
'www.mthosting.net
'Per User Spam Folder
SpamFolder = "Junk Mail"
SpamRule = "Spam Junk Folder"
SpamDeleteRule = "Spam Delete"
SpamScore = "**********"

Set HmailCom = CreateObject("hMailServer.Application")
For Domaincnt = 0 to HmailCom.Domains.Count - 1
	Set Domain = HmailCom.Domains.Item(Domaincnt)

	For Accountcnt = 0 to Domain.Accounts.Count - 1
		Set Account = Domain.Accounts.Item(Accountcnt)
		HasRule = False
		For Rulescnt = 0 to Account.Rules.Count - 1

			If Account.Rules.item(Rulescnt).Name = SpamRule then
				'Spam Rule Exists.
				HasRule = True
			end if
		Next
			
		'Rules Does Not Exist so lets create it.
		If not HasRule Then
			Set obRule = Account.Rules.Add
			obRule.Name = SpamRule
	
			'Check Header for Score
			Set obcriteria = obRule.Criterias.Add
			obCriteria.UsePredefined = false
			obCriteria.HeaderField = "X-Spam-Level"
			obCriteria.MatchType = 2 'Contains
			obCriteria.MatchValue = SpamScore
			obCriteria.Save
			
			'Create Action
			Set obAction = obRule.Actions.Add
			obAction.Type = 4 ' Move to imap Folder
			obAction.IMAPFolder = SpamFolder
			obAction.Save
	
			'Save Rule
			obRule.Save
		End if
	Next
Next
--Updated Fixed Looping Error
Last edited by mthosting on 2007-06-03 18:16, edited 1 time in total.

User avatar
simbolo
New user
New user
Posts: 1
Joined: 2006-12-17 22:56
Location: Manchester, England
Contact:

Post by simbolo » 2006-12-17 23:06

I tried the above script and an error was generated in the log:

Error 800403E9 - No access to this property/method. Ensure that hMailServer.Application.Authenticate() is called with proper login credentials.

And also, the Spamassassin for Win32 seems to run so so much better than the Perl version which took ages to install, and even then it generated blank messages even after hours of tinkering with its settings.

tonda
Normal user
Normal user
Posts: 93
Joined: 2006-10-20 14:13
Location: CZ

Post by tonda » 2006-12-18 00:29

For anybody, who do not want to install and configure Perl or Cygwin I can recommend sawin32 (see Sourceforge). Project consists of standalone .exe files, configuration is very easy, spamd can be easily run as service using srvany.exe and instsrv.exe. I have not found any problems running this version.

Shiloh
Normal user
Normal user
Posts: 163
Joined: 2006-04-14 00:00

Post by Shiloh » 2006-12-18 18:22

As far as I understand it, all they did with sawin32 was tweak the Perl code a little bit and then use a Perl to EXE compiler to generate the EXE files with the Perl libraries and executable built it. It is a bloatware approach. I think it is a decent solution for small volumes of email.

For higher volumes, run SpamD on FreeBSD or Linux and connect to SpamD using spamc.exe (the one compiled using C) or my COM object. SpamAssassin was written for Unix, and it was tested for Unix. You can get it to work on Windows, but the application does not perform well on Windows. It is just not written to properly take advantage of Windows. It is really written with Unix in mind.

Additionally, the sawin32 version is not written for Windows and tweaked to get the most performance possible with Windows. The sawin32 version is just a port with some of the obvious bugs corrects and Perl compiled into it. A true Windows port could perform much better than sawin32. I have nothing against sawin32, but I would not recommend it for anybody that has to process a lot of email.

mthosting
Normal user
Normal user
Posts: 38
Joined: 2006-06-21 01:51
Location: NYC
Contact:

Post by mthosting » 2006-12-18 18:34

simbolo wrote:I tried the above script and an error was generated in the log:

Error 800403E9 - No access to this property/method. Ensure that hMailServer.Application.Authenticate() is called with proper login credentials.

And also, the Spamassassin for Win32 seems to run so so much better than the Perl version which took ages to install, and even then it generated blank messages even after hours of tinkering with its settings.
Sorry I use helm so i have authentication disabled.

Add:

Code: Select all

call hMailCom.Authenticate ("Administrator", "your-admin-password")
after:

Code: Select all

Set HmailCom = CreateObject("hMailServer.Application") 

tonda
Normal user
Normal user
Posts: 93
Joined: 2006-10-20 14:13
Location: CZ

Post by tonda » 2007-01-03 15:38

There is new version of sawin32, which incorporates SpamAssassin 3.1.7.

8BALL
New user
New user
Posts: 5
Joined: 2006-03-27 16:08

Tutorial

Post by 8BALL » 2007-02-12 14:46

Hi

I have to move our mail server to a new pc and need to reinstall spamassasin. The tutorial mentioned in the how to's is no longer available.

Does anyone have a copy of the guide for me?

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-02-12 16:09


tube
New user
New user
Posts: 21
Joined: 2007-02-14 21:35
Location: Germany

Post by tube » 2007-02-18 10:03

I'm using this code:

Code: Select all

Sub OnDeliverMessage(oMessage) 
   fname = oMessage.filename 
   Dim infile, testfile, sh 
   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 
   Set sh = CreateObject("WScript.Shell") 
    
   Dim cmd, rc 
   cmd = "cmd /c perl -S -T -w d:\perl\bin\spamassassin < """ & testfile & """ > """ & infile & """" 
   rc = sh.Run( cmd , 0 , TRUE) 
   result.Value = 0 
   fso.Deletefile testfile 
   Set fso = Nothing 
end sub
and it seems to actually start Spamassassin. It also generates the e-mail, BUT: I get empty headers in Outlook showing all the header-stuff in the mail-body :x

The original message begins with (faked the details):

Code: Select all

Return-Path: <xxxxx@yahoo.de>
X-Original-To: dennis@yyyy.de
Delivered-To: eeeee@server2.rrrrrr.de
Received: from rrrrr.mail.ukl.yahoo.com (rrrrr.mail.ukl.yahoo.com [217.12.12.12])
	by eeeee@server2.rrrrrr.de (Postfix) with SMTP id 10CFF8FE6F
	for <dennis@yyyy.de>; Sun, 18 Feb 2007 09:45:33 +0100 (CET)
The message generated from SA begins with (also details faked):

Code: Select all

Return-Path: <xxxxx@yahoo.de>

X-Spam-Checker-Version: SpamAssassin 3.1.8 (2007-02-13) on home
X-Spam-Status: No, score=2.6 required=10.0 tests=AWL,MISSING_HB_SEP
	autolearn=no version=3.1.8 on home
X-Original-To: dennis@yyyy.de

Delivered-To: eeeee@server2.rrrrrr.de

Received: from rrrrr.mail.ukl.yahoo.com (rrrrr.mail.ukl.yahoo.com [217.12.12.12])

	by server2.rrrrrr.de (Postfix) with SMTP id 10CFF8FE6F

	for <dennis@yyyy.de>; Sun, 18 Feb 2007 09:45:33 +0100 (CET)
There is also an empty line every second line. In fact spamassassin seems to replace a 0d0a (line break) with 0d0d0a.

I'm using the Windows-compiled version of SA. Maybe this is the reason of the Unix-style Line breaks!? But how can I fix this?

Any suggestions?

tube
New user
New user
Posts: 21
Joined: 2007-02-14 21:35
Location: Germany

Post by tube » 2007-02-25 19:54

OK, now I got it. I now use the stuff from http://sawin32.sourceforge.net and it works well.

3 general SA questions:
1)
I've got c:\sawin\SpamAssassin-win32\etc\spamassassin where the local.cf is located. Are the .cf files in c:\sawin\SpamAssassin-win32\share\spamassassin loading automatically?

2)
How do I set SA to German so that the texts in 30_text_de.cf are used.

3)
I've set the update like this: sa-update.exe --nogpg --updatedir \sawin\SpamAssassin-win32\share\spamassassin\
But in this directory a \updates_spamassassin_org is created. Can't I just update to \sawin\SpamAssassin-win32\share\spamassassin\ somehow or is there a reason that the subdir is created?

Sorry - I'm a newbie to the SA :roll:

[edit]: Noone answers so I'm on myself - like allways:

1) yes

2) It's a bug in the latest version

3) The files are used, even if the foldername is "updates_spamassassin_org..."

:?

joncolby
Normal user
Normal user
Posts: 43
Joined: 2007-03-17 05:16

Post by joncolby » 2007-03-17 05:18

I cannot access the how to on link number 6, does anyone have it saved on their computer or know what to do to install spam assasin from scratch, I also am trying to hunt down help installing squirlmail too.
thank you.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2007-03-17 15:21

Try here for the howto: http://64.142.36.76/howtosa.html

Lucas266
New user
New user
Posts: 4
Joined: 2007-03-29 08:38

Post by Lucas266 » 2007-04-23 15:48

I've set all of the above up and it appears to be working very well.

There is one problem though, when I check my mail through the web-interface (squirrelmail) all the e-mails have no subject and no content...
This is very weird because when I download the e-mail through POP it's all fine.

Does anybody know what could be causing this?

User avatar
quantumrider
Normal user
Normal user
Posts: 82
Joined: 2007-05-04 17:31

Post by quantumrider » 2007-06-16 16:11

hi,

I've used a quick and excellent guide to setup Spamassassin posted by bazporter here: http://www.hmailserver.com/forum/viewto ... ight=razor

he also helped me further to set it up, below is a script I ended up with, I've setup 2 email addresses, first is to be intentionally spammed, no legitimate email ever will make it to this email address, second is for forwarding spam emails missed by Spamassassin in this setup as attachments.

Could you guys review it, and possibly I would also like to delete the emails permanently that are going to the 2 accounts, I am still not sure how to do that right...

As far as I can tell it works, however since there is no way to get the success notice out of SA-learn as far as I can tell, I tried the piping I also tried --dump, but without success, perhaps someone with SA-learn experience could show us how to get some feedback to see if learning took place?

I made some changes to capture the Debugging info and now I get this in the log:

Code: Select all

[2192] info: config: failed to parse line, skipping: use_pyzor 0
Does anyone know what that means?

Also, I am hoping for some additional ideas and improvements if any?

Does anyone know of a sure fire way to get spam flowing to the particular email address so we can feed it to SA-learn?

Would be really great to be able to disable Spam protection in hmailserver for those 2 accounts...

Code: Select all



      Sub OnDeliverMessage(oMessage)

oMessageSubject = oMessage.Subject

If InStr(oMessageSubject,"[SPAM]") > 0 Then exit Sub 'spam = true

'	If InStr(oMessage.To,".files") > 0 Then oMessage.Subject = "[file] " & oMessageSubject :oMessage.Save :exit sub

If oMessage.HeaderValue("X-Spam-Flag") = "YES" Then oMessage.Subject = "[SPAM] " & oMessageSubject :oMessage.Save :exit sub

   ' Use SpamC (true) or SpamAssassin (false)
   const cUseSpamC = true

   set oFSO = createObject("Scripting.FileSystemObject")
   set oWSO = createObject("WScript.Shell")

   ' Capture the message filename
   sFname = oMessage.filename

   ' Check if the input file really exists
   if not oFSO.FileExists(sFname) Then :Result.Value = 0 :exit sub

   oInfile = oFSO.GetAbsolutePathName(sFname) :oTestfile = oInfile & ".tmp" :oFSO.CopyFile oInfile, oTestfile

   ' Create command strings
   cmdSA = "cmd /c C:\SA\spamassassin --configpath=c:\sa\share\spamassassin --siteconfigpath=c:\sa\etc\spamassassin < """ & oTestfile & """ > """ & oInfile & """"
   cmdSC = "cmd /c C:\sa\spamc < """ & oTestfile & """ > """ & oInfile & """"

   cmdlearn = "cmd /c c:\SA\sa-learn.exe --username=Administrator --spam --sync " & oTestfile' & "  >> c:\logs\sa-learnspam2.log 2>&1"

   If instr(oMessage.To,"spamme@crm20.com") > 0 Then rcSA = oWSO.Run(cmdlearn , 0 , true) :oFSO.Deletefile oInfile :oFSO.Deletefile oTestfile :Result.Value = 0 :exit Sub

      If instr(oMessage.To,"mustbespam@crm20.com") > 0 Then

   Set atta = oMessage.Attachments

intCC = oMessage.Attachments.Count - 1

For x = 0 To intCC
Set att = atta.Item(x)

pth = "c:\tmp\" & att.Filename

att.SaveAs( pth )
cmdlearn = "cmd /c c:\SA\sa-learn.exe --username=Administrator --spam --sync --D " & pth & "  >> c:\logs\sa-learnspam.log 2>&1"
   
   rcSA = oWSO.Run(cmdlearn , 0 , true)
   oFSO.Deletefile pth

Next 
exit Sub
End if


   if cUseSpamC Then rcSC = oWSO.Run(cmdSC , 0 , true) :else rcSA = oWSO.Run(cmdSA , 0 , true)' use SpamC or Run SpamAssassin

   ' Failsafe: In the event an error causes a zero byte msg
   if oFSO.GetFile(oInfile).Size = 0 Then oFSO.CopyFile oTestfile, oInfile

   oFSO.Deletefile oTestfile
   Result.Value = 0

   set oFSO = nothing
   set oWSO = Nothing

end sub

Image

User avatar
quantumrider
Normal user
Normal user
Posts: 82
Joined: 2007-05-04 17:31

Post by quantumrider » 2007-06-18 00:45

Hi,

there is a problem...

using above script I posted before, I added a few lines to it and a new header in spamd configuration, however, the message object in script doesn't have the new headers, is there a way to re-read the email modified by spamassassin to get those headers or any other way?

I know i could construct some fso little script to read and parse the new email file saved by spamassassin but that would be resources problem...

here is the code:

Code: Select all

'oMessage.Save
testvalue = CInt(oMessage.HeaderValue("X-Spam-Score"))

If testvalue > 6.3 Then oMessage.Subject = "[6+] " & oMessageSubject :oMessage.Save :Else :oMessage.Subject = "[6-] " & oMessageSubject :oMessage.Save

if I remarked the first line you see there the message saved is the version from before the spamassassin does it's work, so that can't be used.

currently nothing is added to the subject, I plan to set the result.value according to the score

how can we load the email into message object after spamassassin rewrote it to read the new headers?

I think perhaps creating a new sub? we can then load the message in the new sub and read headers there? will the new sub load the new message from disk?

-ark
Image

snowbird
New user
New user
Posts: 4
Joined: 2007-06-03 02:15

Post by snowbird » 2007-07-01 15:56

Hello,

I have use the standard script in the thread for integrating Spamassassin into hMailServer.
I dont use the cywin version.

My problem is that tempfiles created on c:\ are not deleted...
the files look like .spamassassinxxxxxxxtmp

Am i the only one experiencing this problem?

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2007-07-01 21:14

Does spamassassin / hmail have modify permissions on the temp folder? If not this is why they are left behind.

Post Reply