HOWTO: Using SpamAssassin with hMailServer V4
I am not shure which temp directory you mean?
As far as i can see the owner of these temp files is the Administrator group.
07-07-2007 14:30 7.189 INGEBOUWD\Administrator .spamassassin1424MbTHZCtmp
06-07-2007 18:30 11.145 INGEBOUWD\Administrator .spamassassin147674MCbktmp
06-07-2007 18:30 15.253 INGEBOUWD\Administrator .spamassassin1476CfyUQYtmp
06-07-2007 18:30 6.558 INGEBOUWD\Administrator .spamassassin1476Mg40nMtmp
06-07-2007 18:30 69 INGEBOUWD\Administrator .spamassassin1476Mqy5JDtmp
In the script I use from this thread I dont see any temp directory mentioned as well?
Sub OnDeliverMessage(oMessage)
'get the filename of the message
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
cmd = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
fso.deletefile testfile
result.value = 0
End Sub
Any help is welcome...
Maarten
As far as i can see the owner of these temp files is the Administrator group.
07-07-2007 14:30 7.189 INGEBOUWD\Administrator .spamassassin1424MbTHZCtmp
06-07-2007 18:30 11.145 INGEBOUWD\Administrator .spamassassin147674MCbktmp
06-07-2007 18:30 15.253 INGEBOUWD\Administrator .spamassassin1476CfyUQYtmp
06-07-2007 18:30 6.558 INGEBOUWD\Administrator .spamassassin1476Mg40nMtmp
06-07-2007 18:30 69 INGEBOUWD\Administrator .spamassassin1476Mqy5JDtmp
In the script I use from this thread I dont see any temp directory mentioned as well?
Sub OnDeliverMessage(oMessage)
'get the filename of the message
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
cmd = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
fso.deletefile testfile
result.value = 0
End Sub
Any help is welcome...
Maarten
Restarting from the beginning
Hi all,
although this thread is full of valuable information, it is very hard for a beginner to set up Spamassassin properly.
Espeacially setting up the event handler script in hMailServer can become very annoying if you are looking for certain features spread over two or more code examples.
Therefore I reviewed all the code snippets from this thread (and a few others) and wrote a (hopefully) well documented event handler script that is highly configurable to fit at least the needs of low volume users. It does have the following features:
I hope you'll like it... Please reply here in this forum to any issues with the script or feature recommendations. If you feel the need to edit this script, make your changes configurable and share the result to the hMailServer forum.
Thanks goes to all contributors to this thread and this forum. Without you, this script would not have been possible.
Update 2007-08-07: Fixed bug where SAHI_auto_discard_score wasn't causing the mail to be deleted.
HUGE SCRIPT INCOMING:
although this thread is full of valuable information, it is very hard for a beginner to set up Spamassassin properly.
Espeacially setting up the event handler script in hMailServer can become very annoying if you are looking for certain features spread over two or more code examples.
Therefore I reviewed all the code snippets from this thread (and a few others) and wrote a (hopefully) well documented event handler script that is highly configurable to fit at least the needs of low volume users. It does have the following features:
- Configurable Bayesian learning
- Configurable for scanning outgoing and/or incoming mails
- Auto discarding of mails above configurable spam score
- Freely configurable for using spamc, spamassassin, sa-learn, etc.
- Scans incoming mails over SMTP or POP
- Configurable logging to hMailServers hmailserver_events.log
7. After that follow the installation instructions included in the script.john25uk wrote:INSTALLING SPAMASSASSIN
Useful sites:
1.Perl for Windows - SITE
2.Perl for Windows - INSTALLER
3.SpamAssassin.org - SITE
4.SpamAssassin - ZIP DOWNLOAD
5.NMAKE
6.Really good how to install SpamAssassin tutorial
Start by downloading and saving no's 2, 4, and 5 - you will need them for the spamassassin install tutorial (6)
Follow the instructions on link 6. HINTS: type the names of the perl modules exactly as shown, including lowercase and capitals. Ignore from Part X onwards for now, but download the Windows GUI in Part XI, its good. Install everything to the default directories also.
I hope you'll like it... Please reply here in this forum to any issues with the script or feature recommendations. If you feel the need to edit this script, make your changes configurable and share the result to the hMailServer forum.
Thanks goes to all contributors to this thread and this forum. Without you, this script would not have been possible.
Update 2007-08-07: Fixed bug where SAHI_auto_discard_score wasn't causing the mail to be deleted.
HUGE SCRIPT INCOMING:
Code: Select all
'-----------------------------------------------------------------------------
'Script:
' Spamassassin hMailServer Integration (SAHI)
'
'Synopsis:
' A configurable script to integrate Spamassassin into hMailServer
'
'Script version:
' 1.1
'
'Release date:
' 2007-08-07
'
'Features:
' - Configurable Bayesian learning
' - Configurable for scanning outgoing and/or incoming mails
' - Auto discarding of mails above configurable spam score
' - Freely configurable for using spamc, spamassassin, sa-learn, etc.
' - Scans incoming mails over SMTP or POP
' - Configurable logging to hMailServers hmailserver_events.log
'
'Limitations:
' - Not meant for use in high volume environments
' - No builtin batch support for Bayesian learning
' - No redirection of spam into different IMAP folder (this must be
' configured in hMailServer)
' - No general userprefs support for scanning/learning
' - No general support for checksum services such as dcc, pyzor, or razor
'
'Requirements:
' - Requires hMailServer, Perl and Spamassassin
' to be successfully installed and the pathes to Perl and
' Spamassassin to be assigned in your PATH variable;
' In the following Spamassassin stands as a synonym for
' either spamc/spamd, spamassassin or some other
' spamassassin derivate, you can configure your prefered
' Spamassassin flavour in the config part below;
' - Requires .NET to be installed - otherwise
' command output redirection will not work and render this
' script useless; tested with .NET 2.0 but other versions may
' work also
' - Requires hMailServer 4.4
'
'Installation:
' 1. Append this code to the end of your EventHandlers.vbs
' file of hMailServer
' 2. Configure the script with the variables below
' 3. Change the OnAcceptMessage handler as follows (obviously
' without the comment quotes):
'
' Sub OnDeliverMessage(oMessage)
' SAHI_processMessage oMessage
' End Sub
'
' 4. Reload your hMailServer scripts afterwards or restart hMailServer
'
'Tested with:
' hMailServer 4.4 (B270) (polling external POP accounts)
' Perl 5.8.8 (820)
' Spamassassin 3.2.2
' Windows XP (latest patch level as at time of writing; .NET framework 2.0)
'
'History:
' 2007-08-05 - 1.0 - Soeren Weber:
' Initial version inspired by the hmailserver.com forum
' discussion "HOWTO: Use SpamAssassin with hMailServer"
'
' 2007-08-07 - 1.1 - Soeren Weber:
' Fixed bugs were SAHI_auto_discard_score wasn't causing the mail to be
' deleted
'
'-----------------------------------------------------------------------------
'Start configure the script here
Const SAHI_domain_received_header = "from myserver ([127.0.0.1]) by example.com with hMailServer ;"
'Possible values:
' Any string that uniquely identifies an outgoing mail
'This string must uniquely identify any outgoing mail that is sent
'from your local domain to an arbitrary recipient by its "Received"
'mail header
Const SAHI_scan_outgoing_mails = 0
'Possible values:
' 0 - Don't check outgoing mails for spam
' 1 - Check outgoing mails for spam
'If you trust your local users you can set this option to 0 to
'skip the check of outgoing mails
Const SAHI_scan_incoming_mails = 1
'Possible values:
' 0 - Don't check incoming mails for spam
' 1 - Check incoming mails for spam
'This option should be set to 1 to activate spam checking for all
'incoming mails; Why else should you have installed Spamassassin?
Const SAHI_add_spam_check_status_header = 0
'Possible values:
' 0 - Don't add an additional header field
' 1 - Add additional mail header field
'In case this value is set to 1, an additional X-Spam-Check-Status will be
'added to the mail, signaling the result of this script; Possible header
'values are:
' Skipped - This will be set if the spam check was skipped due to
' having set SAHI_scan_outgoing_mails or SAHI_scan_incoming_mails
' respectivly to 1
' Checked - This is set if the spam check could be successfully
' applied
' Error - This is set in case the spam check was aborted due to errors
' during processing of the mail by this script
'NOTE: Due to how IMAP works, this header field as also
'Spamassassins own additional header fields will be added to all
'incoming mails unconditionally. For outgoing mails, the headers will be
'added for the mail that was sent from hMailServer to the destination server
'but not to the copy that may be stored in your "Sent" folder;
'It is recommended to better set this value to 0 in case you have set
'SAHI_use_learn_mailboxes to 1. This may negativly influence the results
'of the Bayesian filter rules if you don't add this header field to your
'Spamassasin configuration using the bayes_ignore_header parameter;
'Besides the above mentioned keyword values for this header field, some
'further information may be appended to the field
Const SAHI_auto_discard_score = 12
'Possible values:
' 0 - No auto discarding will be used
' 1 .. n - Integer spam score needed to cause the mail to be discarded
'If the spam check results are above this threshold value, the mail will
'automatically discarded by this script; Usually you should set this to
'the same value as Spamassassins config item bayes_auto_learn_threshold_spam;
'If you are uncertain about the reliability of your Spamassassin rules
'you should avoid discarding mails, so that they are still be delivered
'to your recipients; If you don't want to discard the spam but move it
'to a different IMAP folder, use hMailServer rules; See documentation and
'forum of hMailServer for how this works
Const SAHI_default_scan_command_line = "%comspec% /c spamassassin -e"
'Const SAHI_default_scan_command_line = "%comspec% /c perl -S -T -w spamassassin -e"
'Const SAHI_default_scan_command_line = "%comspec% /c spamc -E -s 512000"
'Const SAHI_default_scan_command_line = "%comspec% /c WinSpamC.exe -t 15"
'Possible values:
' Command line used to start Spamassassin
'Command line that will be used to check emails with Spamassassin; In-
'and outfile parameter will be added by this script, so avoid setting
'them
Const SAHI_alternate_scan_command_line = ""
'Possible values:
' Command line used to start Spamassassin
'Alternate command line that will be used to check emails with
'Spamassassin in case the SAHI_default_scan_command_line failed with an error;
'You can leave this empty if you don't need alternate command processing;
'In- and outfile parameter will be added by this script, so avoid setting
'them; This parameter is useful eg. if you are using spamc for the default
'and running into an error. In this case you may run Spamassassin directly
Const SAHI_use_learn_mailboxes = 1
'Possible values:
' 0 - Don't use ham/spam/forget mailboxes
' 1 - Use ham/spam/forget mailboxes
'If set to 1 this script will cause any mail that will be sent internally to
'the SAHI_learn_ham_mailbox, SAHI_learn_spam_mailbox or
'SAHI_learn_forget_mailbox to be processed by your Bayesian learning tool;
'There may be differnt ways how to feed your tool, therefore this option is
'set to 0 by default; If you use this feature, the mail that should be learned
'is expected to be attached to a forwarding mail; In case you are using
'SquirrelMail, I recommend using the spam_buttons" plugin
Const SAHI_learn_ham_mailbox = "report_ham@example.com"
'Possible values:
' Fully quallified local email address
'You only need to set this if you have SAHI_use_learn_mailboxes set to 1;
'Replace at least the <example.com> with the domain hMailServer is
'running on; You are free to change the mailbox name aswell; There must
'be a mailbox configured in hMailServer server with this name, because
'otherwise mails sent to this address will not be accepted by hMailServer.
'The hMailServer mailbox will not fill with mails if SAHI_use_learn_mailboxes
'is set to 1
Const SAHI_learn_spam_mailbox = "report_spam@example.com"
'Possible values:
' Fully quallified local email address
'You only need to set this if you have SAHI_use_learn_mailboxes set to 1;
'Replace at least the <example.com> with the domain hMailServer is
'running on; You are free to change the mailbox name aswell; There must
'be a mailbox configured in hMailServer server with this name, because
'otherwise mails sent to this address will not be accepted by hMailServer.
'The hMailServer mailbox will not fill with mails if SAHI_use_learn_mailboxes
'is set to 1
Const SAHI_learn_forget_mailbox = "report_purgative@example.com"
'Possible values:
' Fully quallified local email address
'You only need to set this if you have SAHI_use_learn_mailboxes set to 1;
'Replace at least the <example.com> with the domain hMailServer is
'running on; You are free to change the mailbox name aswell; There must
'be a mailbox configured in hMailServer server with this name, because
'otherwise mails sent to this address will not be accepted by hMailServer.
'The hMailServer mailbox will not fill with mails if SAHI_use_learn_mailboxes
'is set to 1
Const SAHI_learn_command_line = "%comspec% /c sa-learn --"
'Possible values:
' Command line used to start sa-learn
'Command line that will be used to run the Bayesian learning tool in case
'SAHI_use_learn_mailboxes is set to 1; The learn type (ham, spam,
'forget) will be appended at the end of this command during runtime; Due to
'the way how hMailServer works, it is 'not wise to use userprefs for the
'Bayesian learning tool
Const SAHI_trace_level = 4
'Possible values:
' One of the below defined SAHI trace levels
'You can adjust the amount of trace that is written to the trace file
'hmailserver_events.log by setting this value; Eg. if you set the
'variable to SAHI_trace_warning, all traces are written that are either
'emergency, alert, critical, error or warning but no traces for notice,
'information and debug; To turn tracing off, set this variable to 0;
'For production you should set this value a lesser equal of 4
'(SAHI_trace_error) or 5 (SAHI_trace_warning) especially if you are
'running high volume
'Stop configure the script here; No more changes should be necessary after
'this line; If you feel the need to edit this script, make your changes
'configurable and share the result to the hMailServer forum
'-----------------------------------------------------------------------------
'SAHI trace levels
Const SAHI_trace_none = 0
Const SAHI_trace_emergency = 1
Const SAHI_trace_alert = 2
Const SAHI_trace_critical = 3
Const SAHI_trace_error = 4
Const SAHI_trace_warning = 5
Const SAHI_trace_notice = 6
Const SAHI_trace_information = 7
Const SAHI_trace_debug = 8
Dim SAHI_trace_str(8)
SAHI_trace_str(0) = "NONE"
SAHI_trace_str(1) = "EMERGENCY"
SAHI_trace_str(2) = "ALERT"
SAHI_trace_str(3) = "CRITICAL"
SAHI_trace_str(4) = "ERROR"
SAHI_trace_str(5) = "WARNING"
SAHI_trace_str(6) = "NOTICE"
SAHI_trace_str(7) = "INFORMATION"
SAHI_trace_str(8) = "DEBUG"
Const SAHI_version = "1.1"
Dim SAHI_sh
Set SAHI_sh = CreateObject("WScript.Shell")
Dim SAHI_fso
Set SAHI_fso = CreateObject("Scripting.FileSystemObject")
Dim SAHI_trace_id
'-----------------------------------------------------------------------------
' OnAcceptMessage callback
'-----------------------------------------------------------------------------
Sub SAHI_processMessage(oMessage)
'Synopsis:
' This is the working horse to process mail to Spamassassin; note that you
' have to call this Sub by Reference for the oMessage parameter, because
' additional mail header may be added to the message; This script will set
' Result.Value to:
' 0 - ham found, spam found while it is below SAHI_auto_discard_score
' or script ran into an error (causing mail to be delivered)
' 1 - ham/spam processed by Bayesian learning tool, spam found while it is
' above SAHI_auto_discard_score (causing mail to be discarded)
SAHI_trace_id = oMessage.id & " | " & oMessage.HeaderValue("Message-ID")
SAHI_trace SAHI_trace_information, "SAHI_Version: " & SAHI_version
SAHI_trace SAHI_trace_notice, "SAHI_processMessage: From: " & oMessage.from & " To: " & oMessage.to & " Subject: " & oMessage.subject & " Filename: " & oMessage.filename
'Lets do some consistency checks first
If SAHI_fso.FileExists(oMessage.filename) = 0 Then
SAHI_trace SAHI_trace_error, "SAHI_processMessage: File " & oMessage.filename & " not found - delivering mail"
Result.Value = 0
Exit Sub
End If
Dim mail_file
mail_file = SAHI_fso.GetAbsolutePathname(oMessage.filename)
'Find out direction of this mail
Dim is_outgoing
is_outgoing = SAHI_isOutgoing(oMessage.HeaderValue("Received"))
'Learn about ham/spam/forget if configured
If is_outgoing <> 0 Then
If SAHI_use_learn_mailboxes = 0 Then
SAHI_trace SAHI_trace_debug, "SAHI_processMessage: Usage of learn mailboxes disabled in configuration"
ElseIf SAHI_learn(oMessage, mail_file) <> 0 Then
'Stop further processing if this mail was feed to Bayesian learning tool
SAHI_trace SAHI_trace_notice, "SAHI_processMessage: File " & oMessage.filename & " was feed to Bayesian learning tool - discarding mail"
Result.Value = 1
Exit Sub
End If
End If
'We may want to skip checking outgoing or incoming mails
Dim direction_str
Dim check_mails
If is_outgoing <> 0 Then
direction_str = "outgoing"
check_mails = SAHI_scan_outgoing_mails
Else
direction_str = "incoming"
check_mails = SAHI_scan_incoming_mails
End If
Dim rc
SAHI_doScan rc, oMessage, check_mails, direction_str
If rc = 0 Then
Exit Sub
End If
'Finallay lets start scanning for spam; until otherwise noticed we want to
'deliver the mail to the recipient, even if we ran into an error during
'spam check
rc = SAHI_scan(mail_file)
oMessage.RefreshContent()
If rc = 0 Then
SAHI_trace SAHI_trace_notice, "SAHI_processMessage: Mail okay - delivering mail"
Result.Value = 0
If SAHI_add_spam_check_status_header <> 0 Then
SAHI_setHeaderValue oMessage, "X-Spam-Check-Status", "Checked on " & direction_str
End If
ElseIf rc = 1 Then
If SAHI_isAboveDiscardScore(oMessage) <> 0 Then
SAHI_trace SAHI_trace_notice, "SAHI_processMessage: Mail flagged as spam - discarding mail because it is above discard score of " & SAHI_auto_discard_score
Result.Value = 1
Else
SAHI_trace SAHI_trace_notice, "SAHI_processMessage: Mail flagged as spam - delivering mail because it is below discard score of " & SAHI_auto_discard_score
Result.Value = 0
End If
If SAHI_add_spam_check_status_header <> 0 Then
SAHI_setHeaderValue oMessage, "X-Spam-Check-Status", "Checked on " & direction_str
End If
Else
SAHI_trace SAHI_trace_notice, "SAHI_processMessage: Mail processed with errors - delivering mail"
Result.Value = 0
If SAHI_add_spam_check_status_header <> 0 Then
SAHI_setHeaderValue oMessage, "X-Spam-Check-Status", "Error on " & direction_str
End If
End If
End Sub
'-----------------------------------------------------------------------------
' status
'-----------------------------------------------------------------------------
Sub SAHI_doScan(rc, oMessage, check_mails, direction_str)
'Synopsis:
' Returns whether mails should be checked for spam for outgoing or
' incoming direction
'Possible return values:
' 0 - mail shouldn't be checked for spam
' 1 - mail should be checked for spam
rc = 1
If check_mails <> 0 Then
SAHI_trace SAHI_trace_debug, "SAHI_doScan: Spam check enabled on " & direction_str & " mails"
Else
SAHI_trace SAHI_trace_notice, "SAHI_doScan: Spam check skipped on " & direction_str & " mails - delivering mail"
Result.Value = 0
If SAHI_add_spam_check_status_header <> 0 Then
SAHI_setHeaderValue oMessage, "X-Spam-Check-Status", "Skipped on " & direction_str
End If
rc = 0
End If
End Sub
Function SAHI_isOutgoing(received)
'Synopsis:
' Checks Received mail header to decide whether this mail is outgoing or
' incoming
'Possible return values:
' 0 - mail is incoming
' 1 - mail is outgoing
SAHI_trace SAHI_trace_debug, "SAHI_isOutgoing: Received: '" & received & "'"
If InStr(1, received, SAHI_domain_received_header, 1) > 0 Then
SAHI_trace SAHI_trace_information, "SAHI_isOutgoing: Outgoing mail detected"
SAHI_isOutgoing = 1
Exit Function
End If
SAHI_trace SAHI_trace_information, "SAHI_isOutgoing: Incoming mail detected"
SAHI_isOutgoing = 0
End Function
Function SAHI_isAboveDiscardScore(oMessage)
'Synopsis:
' Checks if this Mails spam score is above the SAHI_auto_discard_score
'Possible return values:
' 0 - Mail is below SAHI_auto_discard_score
' 1 - Mail is above SAHI_auto_discard_score
SAHI_isAboveDiscardScore = 0
If SAHI_auto_discard_score = 0 Then
Exit Function
End If
Dim discard_score
discard_score = String(SAHI_auto_discard_score, "*")
Dim mail_score
mail_score = oMessage.HeaderValue("X-Spam-Level")
SAHI_trace SAHI_trace_debug, "SAHI_isAboveDiscardScore: discard_score: " & discard_score & " X-Spam-Level: " & mail_score & " X-Spam-Status: " & oMessage.HeaderValue("X-Spam-Status")
If InStr(1, mail_score, discard_score) > 0 Then
SAHI_trace SAHI_trace_debug, "SAHI_isAboveDiscardScore: Mail is marked to be discarded"
SAHI_isAboveDiscardScore = 1
End If
End Function
'-----------------------------------------------------------------------------
' scanning
'-----------------------------------------------------------------------------
Function SAHI_scan(mail_file)
'Synopsis:
' Checks the mail_file for spam with a call to Spamassassin
'Possible return values:
' -1 - an error occured
' 0 - ham was found
' 1 - spam was found
SAHI_trace SAHI_trace_debug, "SAHI_scan: Checking mail for spam"
SAHI_scan = 0
Dim checked_file
checked_file = mail_file & ".tmp"
Dim cmd
cmd = SAHI_default_scan_command_line & " < """ & mail_file & """ > """ & checked_file & """"
Dim rc
rc = SAHI_executeCommand(cmd)
If rc = 0 Then
SAHI_trace SAHI_trace_information, "SAHI_scan: Ham found"
ElseIf rc = 1 Then
SAHI_trace SAHI_trace_information, "SAHI_scan: Spam found"
SAHI_scan = 1
ElseIf Len(SAHI_alternate_scan_command_line) > 0 Then
SAHI_trace SAHI_trace_warning, "SAHI_scan: Default command failed with error " & rc & "; trying to recover with alternate command"
cmd = SAHI_alternate_scan_command_line & " < """ & mail_file & """ > """ & checked_file & """"
rc = SAHI_executeCommand(cmd)
If rc = 0 Then
SAHI_trace SAHI_trace_information, "SAHI_scan: Ham found"
ElseIf rc = 1 Then
SAHI_trace SAHI_trace_information, "SAHI_scan: Spam found"
SAHI_scan = 1
Else
SAHI_trace SAHI_trace_alert, "SAHI_scan: Error found: Alternate command failed with error " & rc
SAHI_scan = -1
End If
Else
SAHI_trace SAHI_trace_alert, "SAHI_scan: Error found: Default command failed with error " & rc
SAHI_scan = -1
End If
'Even if Spamassassin has flagged the mail as spam, we better ignore it in
'case the resulting file was empty or not present at all
If SAHI_fso.FileExists(checked_file) = 0 Then
SAHI_trace SAHI_trace_alert, "SAHI_scan: Error found: Resulting file not created, see previous messages for probably reported error"
SAHI_scan = -1
ElseIf SAHI_fso.GetFile(checked_file).Size = 0 Then
SAHI_fso.DeleteFile checked_file
SAHI_trace SAHI_trace_alert, "SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
SAHI_scan = -1
Else
SAHI_trace SAHI_trace_debug, "SAHI_scan: Replacing mail file with checked result file"
SAHI_fso.DeleteFile mail_file
SAHI_fso.MoveFile checked_file, mail_file
End If
End Function
'-----------------------------------------------------------------------------
' learning
'-----------------------------------------------------------------------------
Function SAHI_learn(oMessage, mail_file)
'Synopsis:
' Check for feeding of Bayesian learning mailboxes with ham, spam or forget
' We do not care about return values of the tool because the ham, spam
' and forget mailboxes are only virtual and therefore we don't want to
' deliver the mail to any physical mailbox regardless if the tool
' was successful or not
'Possible return values:
' 0 - Mail recipient was not a mailbox configured for Bayesian learning tool
' 1 - Mail was feed to Bayesian learning tool
SAHI_trace SAHI_trace_debug, "SAHI_learn: Checking recipients for Bayesian learning mailbox"
SAHI_learn = 0
Dim rc
Dim i
For i = 0 To oMessage.Recipients.Count - 1
Dim recipient_address
recipient_address = oMessage.Recipients.Item(i).Address
If recipient_address = SAHI_learn_ham_mailbox Then
SAHI_learnFood oMessage, mail_file, "ham"
SAHI_learn = 1
Exit Function
ElseIf recipient_address = SAHI_learn_spam_mailbox Then
SAHI_learnFood oMessage, mail_file, "spam"
SAHI_learn = 1
Exit Function
ElseIf recipient_address = SAHI_learn_forget_mailbox Then
SAHI_learnFood oMessage, mail_file, "forget"
SAHI_learn = 1
Exit Function
End If
Next
SAHI_trace SAHI_trace_debug, "SAHI_learn: Recipient not identified as Bayesian learning mailbox"
End Function
Sub SAHI_learnFood(oMessage, mail_file, salearn_food)
Dim attachment_file
'sa-learn needs extra quoting for curly braces in file names - so avoid them
attachment_file = SAHI_stripIllegalChars(mail_file & ".dat", Array("{", "}"))
SAHI_trace SAHI_trace_debug, "SAHI_learnFood: Processing attachments to Bayesian learning tool using " & attachment_file
Dim i
For i = 0 To oMessage.Attachments.Count - 1
oMessage.Attachments.Item(i).SaveAs(attachment_file)
SAHI_feedMessage attachment_file, salearn_food
SAHI_fso.DeleteFile attachment_file
Next
SAHI_trace SAHI_trace_debug, "SAHI_learnFood: " & i & " attachment(s) processed by Bayesian learning tool"
End Sub
Sub SAHI_feedMessage(mail_file, salearn_food)
Dim cmd
cmd = SAHI_learn_command_line & salearn_food & " """ & mail_file & """"
Dim rc
rc = SAHI_executeCommand(cmd)
If rc = 0 Then
SAHI_trace SAHI_trace_information, "SAHI_feedMessage: Learned about " & salearn_food
Else
SAHI_trace SAHI_trace_critical, "SAHI_feedMessage: Learning about " & salearn_food & " failed with error " & rc
End If
End Sub
'-----------------------------------------------------------------------------
' tools
'-----------------------------------------------------------------------------
Function SAHI_executeCommand(command)
Dim rc
SAHI_trace SAHI_trace_debug, "SAHI_executeCommand: command='" & command
rc = SAHI_sh.Run(command, 0, True)
SAHI_trace SAHI_trace_debug, "SAHI_executeCommand: commad returned with " & rc
SAHI_executeCommand = rc
End Function
Sub SAHI_setHeaderValue(oMessage, header_item, header_value)
oMessage.HeaderValue(header_item) = header_value
oMessage.Save()
End Sub
Function SAHI_stripIllegalChars(str, illegal_chars)
' illegal_chars = Array("", "/", ":", ";", "*", """", "<", ">", "|", "=", "?", "[", "]", Chr(34), Chr(39))
Dim char
For Each char In illegal_chars
str = Replace(str, char, "_")
Next
SAHI_stripIllegalChars = str
End Function
Sub SAHI_trace(level, text)
If level <= SAHI_trace_level Then
EventLog.Write(SAHI_trace_id & " | " & SAHI_trace_str(level) & "(" & level & ") | " & text)
End If
End Sub
Last edited by Shelby on 2007-08-15 08:48, edited 1 time in total.
great script, could you take a look at this?
Hi Shelby,
I am using your script and it is working pretty good. I appreciate your effort!
I was wondering if you could take a look an issue I am having with it.
1. the sa-learn feature does not seem to be working for me. I see this in the logs
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | INFORMATION(7) | SAHI_Version: 1.0"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | NOTICE(6) | SAHI_processMessage: From: "YourStamps - Info" <info@yourstamps.com> To: <report_spam@fujiinternal.com> Subject: Filename: e:\Program Files\hMailServer\Data\{BABA7A77-D6CB-44FB-9105-8674D7F35BF6}.eml"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_isOutgoing: Received: 'from wsms1 ([74.67.146.234]) by mail2.fujifilm.com with hMailServer ; Tue, 14 Aug 2007 19:10:31 -0400'"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | INFORMATION(7) | SAHI_isOutgoing: Outgoing mail detected"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_learn: Checking recipients for Bayesian learning mailbox"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_learnFood: Processing attachments to Bayesian learning tool using E:\Program Files\hMailServer\Data\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_executeCommand: command='%comspec% /c sa-learn --spam "E:\Program Files\hMailServer\Data\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat""
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_executeCommand: commad returned with 1"
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | CRITICAL(3) | SAHI_feedMessage: Learning about spam failed with error 1"
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_learnFood: 1 attachment(s) processed by Bayesian learning tool"
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | NOTICE(6) | SAHI_processMessage: File e:\Program Files\hMailServer\Data\{BABA7A77-D6CB-44FB-9105-8674D7F35BF6}.eml was feed to Bayesian learning tool - discarding mail"
I think it has to do with the '\' in the paths. when I drop to a command prompt and execute this:
%comspec% /c sa-learn --spam "E:\Program Files\hMailServer\Data\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat"
i get an error, but when I execute this:
%comspec% /c sa-learn --spam "E:\\Program Files\\hMailServer\\Data\\\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat"
it works. I think you need to escape the back slashes.
I am using your script and it is working pretty good. I appreciate your effort!
I was wondering if you could take a look an issue I am having with it.
1. the sa-learn feature does not seem to be working for me. I see this in the logs
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | INFORMATION(7) | SAHI_Version: 1.0"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | NOTICE(6) | SAHI_processMessage: From: "YourStamps - Info" <info@yourstamps.com> To: <report_spam@fujiinternal.com> Subject: Filename: e:\Program Files\hMailServer\Data\{BABA7A77-D6CB-44FB-9105-8674D7F35BF6}.eml"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_isOutgoing: Received: 'from wsms1 ([74.67.146.234]) by mail2.fujifilm.com with hMailServer ; Tue, 14 Aug 2007 19:10:31 -0400'"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | INFORMATION(7) | SAHI_isOutgoing: Outgoing mail detected"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_learn: Checking recipients for Bayesian learning mailbox"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_learnFood: Processing attachments to Bayesian learning tool using E:\Program Files\hMailServer\Data\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat"
8036 "2007-08-14 19:10:31.750" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_executeCommand: command='%comspec% /c sa-learn --spam "E:\Program Files\hMailServer\Data\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat""
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_executeCommand: commad returned with 1"
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | CRITICAL(3) | SAHI_feedMessage: Learning about spam failed with error 1"
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | DEBUG(8) | SAHI_learnFood: 1 attachment(s) processed by Bayesian learning tool"
8036 "2007-08-14 19:10:35.157" "26912 | <00c801c7dec8$501aaf20$01030a0a@guadagno.org> | NOTICE(6) | SAHI_processMessage: File e:\Program Files\hMailServer\Data\{BABA7A77-D6CB-44FB-9105-8674D7F35BF6}.eml was feed to Bayesian learning tool - discarding mail"
I think it has to do with the '\' in the paths. when I drop to a command prompt and execute this:
%comspec% /c sa-learn --spam "E:\Program Files\hMailServer\Data\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat"
i get an error, but when I execute this:
%comspec% /c sa-learn --spam "E:\\Program Files\\hMailServer\\Data\\\_BABA7A77-D6CB-44FB-9105-8674D7F35BF6_.eml.dat"
it works. I think you need to escape the back slashes.
To be honest, this was my first VBScript program but I am seriously coding C/C++ for years and also know some other languages very well - like JScript, PHP, bash shell, etc. Usually in all of these languages you are in need of doubling the backslashes if you want to print out a backslash in a hardcoded string like:
This is because the code compiler will replace the double backslashes with single backslashes and afterwards the variable will contain:
Therefore once you have a properly escaped string inside a variable there is no need to escape them any further for output. In the scripts case this should be handled properly - in case VBScript behaves like the other languages I know...
So it seems like a different issue to me. Question: Does only sa-learn fail? What about the call of the spam scanning command? If you are right with your assumption, this must also fail.
My log is showing success for almost the same command line:
The only difference I can see is the space in your path. But this should be handled properly by quoting the file parameter... Strange... If the space in the path is the problem here, this should also fail in case of spam scanning.
Anyway: Do you fullfil the scripts requirements as mentioned at the beginning of the script in the documention part? Which version of Spamassassin are you using? Is this downloaded directly from the Spamassassins homepage or is it some packaged distribution?
Code: Select all
my_string = "C:\\path\\to\\something"
Code: Select all
WScript.Echo(my_string) // results in C:\path\to\something
So it seems like a different issue to me. Question: Does only sa-learn fail? What about the call of the spam scanning command? If you are right with your assumption, this must also fail.
My log is showing success for almost the same command line:
Code: Select all
892 "2007-08-13 22:40:41.312" "99872 | <2208.F0IUS0R+A1A=.1187037588.squirrel@shelby> | DEBUG(8) | SAHI_executeCommand: command='%comspec% /c sa-learn --spam "C:\Programme\hMailServer\Data\_01FADE2E-1FDB-4BFF-933D-6690CDDA2B3A_.eml.dat""
892 "2007-08-13 22:40:42.718" "99872 | <2208.F0IUS0R+A1A=.1187037588.squirrel@shelby> | DEBUG(8) | SAHI_executeCommand: commad returned with 0"
Anyway: Do you fullfil the scripts requirements as mentioned at the beginning of the script in the documention part? Which version of Spamassassin are you using? Is this downloaded directly from the Spamassassins homepage or is it some packaged distribution?
Okay, let's try the following:
1. Search the script for the following line:
and temporarily replace it with:
2. Reload the scripts from inside the hMailServer Administrator tool
3. Process one spam/ham/forget mail
After processing there should be a new log file C:\sa-learn.log indicating the status of the learning performed in step 3. Mine is showing something like:
What does your log file say? Don't forget to undo the change to the script after everything is working fine. The sa-learn.log will not be deleted and therefore will become bigger and bigger over time.
1. Search the script for the following line:
Code: Select all
cmd = SAHI_learn_command_line & salearn_food & " """ & mail_file & """"
Code: Select all
cmd = SAHI_learn_command_line & salearn_food & " """ & mail_file & """ >> ""C:\\sa-learn.log"""
3. Process one spam/ham/forget mail
After processing there should be a new log file C:\sa-learn.log indicating the status of the learning performed in step 3. Mine is showing something like:
Code: Select all
Learned tokens from 1 message(s) (1 message(s) examined)
Hi Shelby,
Firstly, I want to thank you for the great script! This is exactly what I'm looking for!
Although, it doesn't work on my server. The following lines are in the hmailserver_events.log (this is actualy for the registration mail for this forum ):
For as far as I can see, the output that spamc gives, is empty. When I add the line
just before the call for spamc, I see that the file with the mail is fine.
The other strange thing is, that it's lightning fast. Normally that's a goot thing, but performing the command on a command line with d:\mail_file.txt, needs a second or two. also, when I call the main sub with a quick and dirty:
It performs well: the output file is not empty!
Do you have a clue? I tried several things, used spamc, spamassassin, and winspamc, but all with the same results...
Tom
Firstly, I want to thank you for the great script! This is exactly what I'm looking for!
Although, it doesn't work on my server. The following lines are in the hmailserver_events.log (this is actualy for the registration mail for this forum ):
Code: Select all
INFORMATION(7) | SAHI_Version: 1.1
NOTICE(6) | SAHI_processMessage: From: no-reply@hmailserver.com To: tom_hmailserver@vanderduin.com Subject: Welcome to hMailServer.com Forums Filename: d:\hMailServer\Data\{9600083B-C88B-4ED3-9D45-10DE17A994F8}.eml
DEBUG(8) | SAHI_isOutgoing: Received: 'from mail.hmailserver.com ([216.128.26.134]) by mail.vanderduin.com with hMailServer ; Wed, 29 Aug 2007 00:11:21 +0200'
INFORMATION(7) | SAHI_isOutgoing: Incoming mail detected
DEBUG(8) | SAHI_doScan: Spam check enabled on incoming mails
DEBUG(8) | SAHI_scan: Checking mail for spam
DEBUG(8) | SAHI_executeCommand: command=%comspec% /c spamc -E -s 512000 < "D:\hMailServer\Data\{9600083B-C88B-4ED3-9D45-10DE17A994F8}.eml" > "D:\hMailServer\Data\{9600083B-C88B-4ED3-9D45-10DE17A994F8}.eml.tmp"
DEBUG(8) | SAHI_executeCommand: commad returned with: 1
INFORMATION(7) | SAHI_scan: Spam found
ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error
NOTICE(6) | SAHI_processMessage: Mail processed with errors - delivering mail
Code: Select all
SAHI_fso.CopyFile mail_file, "d:\mail_file.txt", True
The other strange thing is, that it's lightning fast. Normally that's a goot thing, but performing the command on a command line with d:\mail_file.txt, needs a second or two. also, when I call the main sub with a quick and dirty:
Code: Select all
dim oApp
set oApp = CreateObject("hMailServer.Application")
call oApp.Authenticate("Administrator", "*******;)")
dim oAccount
set oAccount = oApp.Domains.Item(0).Accounts.Item(1)
Dim oMail
Set oMail=oAccount.IMAPFolders.Item(0).Messages.Item(1323)
SAHI_processMessage oMail
Do you have a clue? I tried several things, used spamc, spamassassin, and winspamc, but all with the same results...
Tom
Just found the answer! I'm using the Spamassassin for Win32 binaries, from http://sawin32.sourceforge.net/ (very easy install! precompiled...) I changed the command to:
(note the .exe), now it's working like a charm!
Tom
Code: Select all
Const SAHI_default_scan_command_line = "%comspec% /c d:\spamassassin\spamc.exe -E -s 512000"
Tom
Hello, I have installed "SAwin32 — SpamAssassin for Win32" in the directory c:\spamassassin. I have setup the following script:
Sub OnDeliverMessage(oMessage)
'get the filename of the message
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
cmd = "c:\spamassassin\spamassassin < """ & testfile & """ > """ & infile & """"
set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
fso.deletefile testfile
result.value = 0
End Sub
But when there is a new mail comming in then I don't get this email in my mailbox. When I check the hmailserver\data directory then I see that the script is running, I see a .eml file comming in and then changing to .eml.tmp and then again to .eml and then the file disapears. But when I look into the log-file af hmailserver I get (I have changed the domain mailbox by xxxxxx.com:
"DEBUG" 4012 "2007-09-02 09:17:35.136" "TransparentTransmissionBuffer::Initialize()"
"SMTPD" 4012 7 "2007-09-02 09:17:35.136" "195.130.137.74" "SENT: 354 OK, send."
"DEBUG" 4012 "2007-09-02 09:17:35.136" "PMADO:SaveObject()"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Adding message to database. File: C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "PMADO:~SaveObject()"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Message added. File: C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Application::SubmitPendingEmail()"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Application::~SubmitPendingEmail()"
"SMTPD" 4012 7 "2007-09-02 09:17:35.136" "195.130.137.74" "SENT: 250 Queued (0.000 seconds)"
"SMTPD" 4012 7 "2007-09-02 09:17:35.152" "195.130.137.74" "RECEIVED: QUIT"
"SMTPD" 4012 7 "2007-09-02 09:17:35.152" "195.130.137.74" "SENT: 221 goodbye"
"TCPIP" 4012 "2007-09-02 09:17:35.152" "Disconnecting socket 1440 for session 7"
"DEBUG" 4012 "2007-09-02 09:17:35.152" "Socket::~Socket(ID: 7)"
"DEBUG" 2764 "2007-09-02 09:17:35.152" "SD::DeliverMessage"
"APPLICATION" 2764 "2007-09-02 09:17:35.152" "SMTPDeliverer - Message 4160: Delivering message from info@xxxxxx2.com to info@xxxxxx.com. File: C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml"
"DEBUG" 2764 "2007-09-02 09:17:35.152" "ClamWinVirusScanner::Scan()"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "ClamWinVirusScanner::Scan() - C:\Program Files\ClamWin\bin\clamscan.exe --database="C:\Documents and Settings\All Users.WINDOWS\.clamwin\db" "{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml" --tempdir="C:\WINDOWS\Temp" - Returned 0"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "ClamWinVirusScanner::~Scan()"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "RuleApplier::ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "RuleApplier::~ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "ScriptServer:FireEvent"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "ScriptServer:~FireEvent"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "SD::_DeliverToLocalAccounts"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "RuleApplier::ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "RuleApplier::~ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "PMADO:CopyMailContentsFrom()"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "PMADO:~CopyMailContentsFrom()"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: File::Move(), Code: HM10027, Description: Could not move the file C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml to C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml. Tried 5 times without success. Windows eror code: 2 (File not found)"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: PersistentMessage::AddObject(), Code: HM10064, Description: Tried to save message in database even though file C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml did not exist."
"DEBUG" 2764 "2007-09-02 09:17:44.636" "AWStats::LogDeliverySuccess"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "SD::~_DeliverToLocalAccounts"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "SMTPDeliverer - Message 4160: Message delivery thread completed."
"DEBUG" 2764 "2007-09-02 09:17:44.636" "PersistentMessage::DeleteObject()"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "PersistentMessage::DeleteFile()"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "PersistentMessage::DeleteObject() - E5"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "SD::~DeliverMessage"
This is the line where the error occurs:
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: File::Move(), Code: HM10027, Description: Could not move the file C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml to C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml. Tried 5 times without success. Windows eror code: 2 (File not found)"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: PersistentMessage::AddObject(), Code: HM10064, Description: Tried to save message in database even though file C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml did not exist."
What can I do about this problem? Can anyone help me to solve it?
Kind regards
Maarten
Sub OnDeliverMessage(oMessage)
'get the filename of the message
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
cmd = "c:\spamassassin\spamassassin < """ & testfile & """ > """ & infile & """"
set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
fso.deletefile testfile
result.value = 0
End Sub
But when there is a new mail comming in then I don't get this email in my mailbox. When I check the hmailserver\data directory then I see that the script is running, I see a .eml file comming in and then changing to .eml.tmp and then again to .eml and then the file disapears. But when I look into the log-file af hmailserver I get (I have changed the domain mailbox by xxxxxx.com:
"DEBUG" 4012 "2007-09-02 09:17:35.136" "TransparentTransmissionBuffer::Initialize()"
"SMTPD" 4012 7 "2007-09-02 09:17:35.136" "195.130.137.74" "SENT: 354 OK, send."
"DEBUG" 4012 "2007-09-02 09:17:35.136" "PMADO:SaveObject()"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Adding message to database. File: C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "PMADO:~SaveObject()"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Message added. File: C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Application::SubmitPendingEmail()"
"DEBUG" 4012 "2007-09-02 09:17:35.136" "Application::~SubmitPendingEmail()"
"SMTPD" 4012 7 "2007-09-02 09:17:35.136" "195.130.137.74" "SENT: 250 Queued (0.000 seconds)"
"SMTPD" 4012 7 "2007-09-02 09:17:35.152" "195.130.137.74" "RECEIVED: QUIT"
"SMTPD" 4012 7 "2007-09-02 09:17:35.152" "195.130.137.74" "SENT: 221 goodbye"
"TCPIP" 4012 "2007-09-02 09:17:35.152" "Disconnecting socket 1440 for session 7"
"DEBUG" 4012 "2007-09-02 09:17:35.152" "Socket::~Socket(ID: 7)"
"DEBUG" 2764 "2007-09-02 09:17:35.152" "SD::DeliverMessage"
"APPLICATION" 2764 "2007-09-02 09:17:35.152" "SMTPDeliverer - Message 4160: Delivering message from info@xxxxxx2.com to info@xxxxxx.com. File: C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml"
"DEBUG" 2764 "2007-09-02 09:17:35.152" "ClamWinVirusScanner::Scan()"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "ClamWinVirusScanner::Scan() - C:\Program Files\ClamWin\bin\clamscan.exe --database="C:\Documents and Settings\All Users.WINDOWS\.clamwin\db" "{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml" --tempdir="C:\WINDOWS\Temp" - Returned 0"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "ClamWinVirusScanner::~Scan()"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "RuleApplier::ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "RuleApplier::~ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.589" "ScriptServer:FireEvent"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "ScriptServer:~FireEvent"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "SD::_DeliverToLocalAccounts"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "RuleApplier::ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "RuleApplier::~ApplyRules"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "PMADO:CopyMailContentsFrom()"
"DEBUG" 2764 "2007-09-02 09:17:43.636" "PMADO:~CopyMailContentsFrom()"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: File::Move(), Code: HM10027, Description: Could not move the file C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml to C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml. Tried 5 times without success. Windows eror code: 2 (File not found)"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: PersistentMessage::AddObject(), Code: HM10064, Description: Tried to save message in database even though file C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml did not exist."
"DEBUG" 2764 "2007-09-02 09:17:44.636" "AWStats::LogDeliverySuccess"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "SD::~_DeliverToLocalAccounts"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "SMTPDeliverer - Message 4160: Message delivery thread completed."
"DEBUG" 2764 "2007-09-02 09:17:44.636" "PersistentMessage::DeleteObject()"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "PersistentMessage::DeleteFile()"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "PersistentMessage::DeleteObject() - E5"
"DEBUG" 2764 "2007-09-02 09:17:44.636" "SD::~DeliverMessage"
This is the line where the error occurs:
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: File::Move(), Code: HM10027, Description: Could not move the file C:\Program Files\hMailServer\Data\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml to C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml. Tried 5 times without success. Windows eror code: 2 (File not found)"
"APPLICATION" 2764 "2007-09-02 09:17:44.636" "Source: PersistentMessage::AddObject(), Code: HM10064, Description: Tried to save message in database even though file C:\Program Files\hMailServer\Data\xxxxxx.com\info\B1\{B1ACD995-E439-4DFC-94F6-FCAD53191232}.eml did not exist."
What can I do about this problem? Can anyone help me to solve it?
Kind regards
Maarten
Shelby,
I can not find any hmailserver_event.log file.
The script is executed by hmailserver can not transfert the email to the right mailbox (see hmailserver_xxxx-xx-xx.log file). I never get the email inside of my mailbox.
When I do a manual test (in command-prompt) than I see that he has added the extra headers. But when I try to implement it inside of hmailserver I don't get the email in my mailbox. It is just like hmailserver is not waiting until spamassassin is done to move the mail to the right mailbox.
Kind regards
Maarten
I can not find any hmailserver_event.log file.
The script is executed by hmailserver can not transfert the email to the right mailbox (see hmailserver_xxxx-xx-xx.log file). I never get the email inside of my mailbox.
When I do a manual test (in command-prompt) than I see that he has added the extra headers. But when I try to implement it inside of hmailserver I don't get the email in my mailbox. It is just like hmailserver is not waiting until spamassassin is done to move the mail to the right mailbox.
Kind regards
Maarten
Hi All,
It's my first post on this subject.
I run a small hosting server for a few of my clients that also handles a (relatively) small volume of mail. Unfortunately, the volume of spam through the server was getting to a point where my clients really wanted something done so I decided to install SpamAssassin.
After trying to follow all the information on here and getting a bit confused, I decided to try and "roll-my-own" to a certain extent.
I downloaded the VBS provided at the beginning of the thread and customised it a bit so it now works (in a slightly convoluted way, but it does work) with the Win32 binaries of SpamAssassin.
This made my life much easier as it means no compiling of code or anything. Just download the binaries and point the VBS script to them.
Don't get me wrong, it's most definitely not great code as I was hacking it together but it does work and hopefully some people here will be able to suggest some improvements.
If you want to do it yourself, here's what you need to do:
1.) Download the VB Script from http://www.ekitsolutions.co.uk/SACheck.zip and place this in the root of your C drive.
2.) Download the Win32 Command Line Tool Binaries for SpamAssasssin, these can be found at http://sawin32.sourceforge.net/ You may need to scroll down a little till you see the ones you need
3.) Extract all these files to c:\spamassassin. This should mean that the executable spamassassin.exe is now located at c:\spamassassin\spamassassin.exe
3.) Make a new folder in the root of your c drive called batch
4.) Modify your hMailServer External Scanner to run the following command (without the double quotes!): "c:\windows\system32\cscript.exe //nologo c:\SaCheck.vbs" and set the return value to 55.
That should be it and your incoming emails should now be scanned with hMailServer.
All there is to be done now is to start using spamc and spamd to speed things up but I've got to look into this a little bit further and the performance currently isn't bad enough to warrant spending much time on it!
Hopefully this will help someone as it means you don't have to worry about compiling code!
If you need to get hold of me personally, email me at adam@picatnet.co.uk as I check my email more than I check forums!
Regards,
Adam
It's my first post on this subject.
I run a small hosting server for a few of my clients that also handles a (relatively) small volume of mail. Unfortunately, the volume of spam through the server was getting to a point where my clients really wanted something done so I decided to install SpamAssassin.
After trying to follow all the information on here and getting a bit confused, I decided to try and "roll-my-own" to a certain extent.
I downloaded the VBS provided at the beginning of the thread and customised it a bit so it now works (in a slightly convoluted way, but it does work) with the Win32 binaries of SpamAssassin.
This made my life much easier as it means no compiling of code or anything. Just download the binaries and point the VBS script to them.
Don't get me wrong, it's most definitely not great code as I was hacking it together but it does work and hopefully some people here will be able to suggest some improvements.
If you want to do it yourself, here's what you need to do:
1.) Download the VB Script from http://www.ekitsolutions.co.uk/SACheck.zip and place this in the root of your C drive.
2.) Download the Win32 Command Line Tool Binaries for SpamAssasssin, these can be found at http://sawin32.sourceforge.net/ You may need to scroll down a little till you see the ones you need
3.) Extract all these files to c:\spamassassin. This should mean that the executable spamassassin.exe is now located at c:\spamassassin\spamassassin.exe
3.) Make a new folder in the root of your c drive called batch
4.) Modify your hMailServer External Scanner to run the following command (without the double quotes!): "c:\windows\system32\cscript.exe //nologo c:\SaCheck.vbs" and set the return value to 55.
That should be it and your incoming emails should now be scanned with hMailServer.
All there is to be done now is to start using spamc and spamd to speed things up but I've got to look into this a little bit further and the performance currently isn't bad enough to warrant spending much time on it!
Hopefully this will help someone as it means you don't have to worry about compiling code!
If you need to get hold of me personally, email me at adam@picatnet.co.uk as I check my email more than I check forums!
Regards,
Adam
Hi Shelby,
First off awesome script I have been looking for something like this, just got it working, and it is processing spam correctly, quick question, I have set the the email to be automatically deleted if it reaches a score of 10 or above.
Const SAHI_auto_discard_score = 10
and I also set Const SAHI_add_spam_check_status_header = 0 as I thought that was the line to make sure the score wasnt printed as part of the email since i only wanted it in the mail header, however the email isnt deleting for scores over 10 and it is giving me a full description in the mail rather than just the mail header, where could i possibly be going wrong?!
for e.g.
Spam detection software, running on the system "Eleanor", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details.
First off awesome script I have been looking for something like this, just got it working, and it is processing spam correctly, quick question, I have set the the email to be automatically deleted if it reaches a score of 10 or above.
Const SAHI_auto_discard_score = 10
and I also set Const SAHI_add_spam_check_status_header = 0 as I thought that was the line to make sure the score wasnt printed as part of the email since i only wanted it in the mail header, however the email isnt deleting for scores over 10 and it is giving me a full description in the mail rather than just the mail header, where could i possibly be going wrong?!
for e.g.
Spam detection software, running on the system "Eleanor", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details.
Thanks Much!!Content preview: VIRUS DETECTED: The attachment(s) of this message was removed
since a virus was detected in at least one of them. [...]
Content analysis details: (31.9 points, 5.0 required)
pts rule name description
---- ---------------------- --------------------------------------------------
0.1 RDNS_NONE Delivered to trusted network by a host with no rDNS
4.4 HELO_DYNAMIC_IPADDR2 Relay HELO'd using suspicious hostname (IP addr
2)
4.2 HELO_DYNAMIC_SPLIT_IP Relay HELO'd using suspicious hostname (Split
IP)
1.6 TVD_RCVD_IP TVD_RCVD_IP
0.0 MISSING_DATE Missing Date: header
0.0 FROM_LOCAL_DIGITS From: localpart has long digit sequence
2.7 FROM_LOCAL_HEX From: localpart has long hexadecimal sequence
2.6 RCVD_NUMERIC_HELO Received: contains an IP address used for HELO
1.0 SPF_FAIL SPF: sender does not match SPF record (fail)
[SPF failed: Please see http://www.openspf.org/why.html?sender= ... er=Eleanor]
1.3 URI_HEX URI: URI hostname has long hexadecimal sequence
2.0 URIBL_BLACK Contains an URL listed in the URIBL blacklist
[URIs: miloe2r.zj.cn]
2.0 URIBL_PH_SURBL Contains an URL listed in the PH SURBL blocklist
[URIs: miloe2r.zj.cn]
2.9 URIBL_JP_SURBL Contains an URL listed in the JP SURBL blocklist
[URIs: miloe2r.zj.cn]
2.1 DNS_FROM_RFC_BOGUSMX RBL: Envelope sender in bogusmx.rfc-ignorant.org
2.5 URIBL_SBL Contains an URL listed in the SBL blocklist
[URIs: miloe2r.zj.cn]
1.5 MSGID_FROM_MTA_HEADER Message-Id was added by a relay
1.0 TVD_PH_SUBJ_META TVD_PH_SUBJ_META
Hi ShelbyShelby wrote:wacko and me figured this out by Private Messaging. In the end it came all down to an outdated hMailserver version. After upgrading to the current stable version (build 270) , everything works fine for wacko.
I the same issue - used build 270 and latested beta still errors with:
SAHI_scan: Error found: Default command failed with error 5
Any help please.
most likely it is due to the command being used to run spamassassin, try changing to the correct path, thats what fixed it for me
Code: Select all
Const SAHI_default_scan_command_line =
Hi Thanks for the reply think i may have conffused the issue tbh.wacko wrote:most likely it is due to the command being used to run spamassassin, try changingto the correct path, thats what fixed it for meCode: Select all
Const SAHI_default_scan_command_line =
SAHI_executeCommand: command='%comspec% /c spamassassin -e < "C:\hMailServer\Data\{D57FD371-2C0D-429C-B1FF-0DED432B56B8}.eml
SAHI_executeCommand: commad returned with 0
That would seem to be working its the learn bit im having problems with.
Ok an update from last post.
Ok mail appears to be being processed for spam in that it gets ****SPAM**** added but on a confirmed spam it errors with error 5.
Normal mail returns 0.
So I assume this is sa-learn part failing ?? as I see nothing in logs that this is running.
I've just gone through three Spam Assassin tutorials and they all leave me confused by the following line:
Copy the backed up configuration files into the site configuration folder, probably c:\perl\site\etc\mail\spamassassin.
Where are the backed up configuration files and where is the site configuration folder?
Copy the backed up configuration files into the site configuration folder, probably c:\perl\site\etc\mail\spamassassin.
Where are the backed up configuration files and where is the site configuration folder?
Hello, first of all, thank you for providing us with your script! I was able to make all this work pretty easily.
But now I'm facing a strange issue. SpamAssassin keeps checking my outgoing messages even if it should be disabled:
After reviewing the headers of the outgoing messages, I found out that they contain the following SpamASsassin header:
So SpamAssassin is atually incorrectly considering them to be incoming, rather than outgoing.
Since I'm new to both, SpamAssassin as well as hMailServer, could anyone just point me in the right direction? I mean - what could be causing this, or what setting is wrong?
These are the versions I'm using:
hMailServer 4.4-B720 against MySQL 5 on the same machine
SpamAssassin 3.2.3 built from source, ActivePerl 5.8.4.810
Any help will be highly appreciated!
Rado
But now I'm facing a strange issue. SpamAssassin keeps checking my outgoing messages even if it should be disabled:
Code: Select all
Const SAHI_scan_outgoing_mails = 0
Code: Select all
X-Spam-Check-Status: Checked on incoming
Since I'm new to both, SpamAssassin as well as hMailServer, could anyone just point me in the right direction? I mean - what could be causing this, or what setting is wrong?
These are the versions I'm using:
hMailServer 4.4-B720 against MySQL 5 on the same machine
SpamAssassin 3.2.3 built from source, ActivePerl 5.8.4.810
Any help will be highly appreciated!
Rado
Thank you Shelby, that was it!Shelby wrote:rado, most probably you haven't configured the parameter SAHI_domain_received_header properly.
While first configuring I skipped this one because I didn't really know what to put in, and I completely forgot about setting it later. Now everything works as expected!
Still a lot to go through to understand all the SA settings, etc, but the basic configurations already works (without bayes) with excellent results in catching spam.
Well, I must have done something wrong because now SA considers all email outgoing, and skips checks on everything!
I believe the trouble is that I have removed the first part of the template value for SAHI_domain_received_header: the "Received: from HOSTNAME (IP)" part, and left only the "by MAILSERVER with hMailServer ;" part.
I did this because the received from part always changes - depending on who is the sender and where is he sending from (locally within our office, or from outside, etc).
Is there any other way for it to distinguish outgoing messages from incoming? Or any other way to set this variable?
Thanks again!
I believe the trouble is that I have removed the first part of the template value for SAHI_domain_received_header: the "Received: from HOSTNAME (IP)" part, and left only the "by MAILSERVER with hMailServer ;" part.
I did this because the received from part always changes - depending on who is the sender and where is he sending from (locally within our office, or from outside, etc).
Is there any other way for it to distinguish outgoing messages from incoming? Or any other way to set this variable?
Thanks again!
-
- New user
- Posts: 1
- Joined: 2007-12-12 20:57
OK, I successfully migrated from Argosoft to hMailServer and got Spamassassin up and running, with the script on this page.
Now, what I would like to do, is to add some code to the script, in order to copy all *.eml files after Spam processing to a certain folder, depending if they are Ham or Spam. So all Ham-eml should be copied to a certain folder, and all the Spam-eml should be copied to another folder, in order to archive all messages and to be able to inspect it afterwards to use it for SA-LEARN.
Since I am not a VBS Coder, I ask you for help. Can anybody provide me with the VBS code to copy the eml Message to another folder (before it's being delivered by hMailServer)?
Thanks in advance
Now, what I would like to do, is to add some code to the script, in order to copy all *.eml files after Spam processing to a certain folder, depending if they are Ham or Spam. So all Ham-eml should be copied to a certain folder, and all the Spam-eml should be copied to another folder, in order to archive all messages and to be able to inspect it afterwards to use it for SA-LEARN.
Since I am not a VBS Coder, I ask you for help. Can anybody provide me with the VBS code to copy the eml Message to another folder (before it's being delivered by hMailServer)?
Thanks in advance
OK, found out myself.
Those two litte lines will do the trick:
Add one section for Ham, Spam and Error right after the lines, where it says "Spam Found" "Ham Found" "Error Found", and the *.eml files will be copied automatically into the according archive folders.
If you have an alternate command line you have to add the sections another three times.
Those two litte lines will do the trick:
Code: Select all
cmd = "%comspec% /c xcopy.exe " & """" & mail_file & """ " & "d:\MailArchive\Ham\"
rc2 = SAHI_executeCommand(cmd)
If you have an alternate command line you have to add the sections another three times.
OK, found out now how to do it natively in VBScript:
This VBScript Line will also do the trick:
This VBScript Line will also do the trick:
Code: Select all
SAHI_fso.CopyFile mail_file, "d:\MailArchive\Ham\", True
- simondsmason
- Normal user
- Posts: 147
- Joined: 2007-11-29 00:52
I am following the installation instructions for SpamAssassin and I am getting an error in the NMAKE. It is failing with an error U1077 and mentions CMD.EXE. I have installed all optional PERL modules as discussed and the makefile appears to work. I am answering N to the C question. Anyone have any thoughts? Thanks.
Simon DS Mason
-
- New user
- Posts: 1
- Joined: 2008-03-08 06:14
Not passing double quote
Hello! I'm using the VBScript from "Adamant" and in the Settings/AntiVirus/External Virus Scanner I put the code "c:\windows\system32\cscript.exe //nologo c:\SaCheck.vbs" BUT when the actual hMailServer calls it, it doesn't put quotes around the path such as "DEBUG" 5884 "2008-03-07 17:44:47.374" "CustomVirusScanner: can() - c:\windows\system32\cscript.exe //nologo c:\SaCheck.vbs C:\Program Files\hMailServer\Data\{A859BD2E-07F2-42E7-8448-A4AC89D355D8}.eml - Returned 89"
I need to either know how to put quotes around the parameter OR if there is a different place I need to call the script from.
Thanks!
I need to either know how to put quotes around the parameter OR if there is a different place I need to call the script from.
Thanks!
I just followed those instructions but I get Returned 89. Is that right? the C:\batch folder is emptyAdamant wrote: 1.) Download the VB Script from http://www.ekitsolutions.co.uk/SACheck.zip and place this in the root of your C drive.
2.) Download the Win32 Command Line Tool Binaries for SpamAssasssin, these can be found at http://sawin32.sourceforge.net/ You may need to scroll down a little till you see the ones you need
3.) Extract all these files to c:\spamassassin. This should mean that the executable spamassassin.exe is now located at c:\spamassassin\spamassassin.exe
3.) Make a new folder in the root of your c drive called batch
4.) Modify your hMailServer External Scanner to run the following command (without the double quotes!): "c:\windows\system32\cscript.exe //nologo c:\SaCheck.vbs" and set the return value to 55.
Code: Select all
CustomVirusScanner::Scan() - c:\windows\system32\cscript.exe //nologo c:\SACheck.vbs C:\Program Files\hMailServer\Data\{053273F7-DCA6-474C-85D3-2B11DB58A275}.eml - Returned 89
Re: HOWTO: Using SpamAssassin with hMailServer
Shelby - thanks for all the work you put in on that script.
I've one question/comment (so far)
You wrote
... so, your text comment says put this in one event, and your commented out code says a different one.
I've tried it both ways. Both invoke spamc just fine - but if SAHI gets run at OnDeliver, modified email doesn't get "caught" by server based rules, but it does when it's run at OnAccept.
Was there some problem with running it at OnAccept? If there was, I suppose whatever it it'll bite me in the backside eventually, but it'd be nice to hear about it in advance...(?)
Best
I've one question/comment (so far)
You wrote
Code: Select all
' 3. Change the OnAcceptMessage handler as follows (obviously
' without the comment quotes):
'
' Sub OnDeliverMessage(oMessage)
' SAHI_processMessage oMessage
' End Sub
I've tried it both ways. Both invoke spamc just fine - but if SAHI gets run at OnDeliver, modified email doesn't get "caught" by server based rules, but it does when it's run at OnAccept.
Was there some problem with running it at OnAccept? If there was, I suppose whatever it it'll bite me in the backside eventually, but it'd be nice to hear about it in advance...(?)
Best
Last edited by bobkoure on 2008-04-12 05:57, edited 1 time in total.
Re:
Maybe just grab a precompiled-for-win32 version at SAwin32? I've been using this (well, successive versions of this) for three or four years, now - no problems.simondsmason wrote:I am following the installation instructions for SpamAssassin and I am getting an error in the NMAKE. ... Anyone have any thoughts? Thanks.
I've been using the spamc/spamd combo (spamd stays resident, so there's less overhead on each call to SA) but there's a spamassassin.exe as well if you just want to see if it works...
Re: HOWTO: Using SpamAssassin with hMailServer
bobkoure, you are right with your observation. Smells fishy. I only remember having troubles with the OnAcceptMessage event and therefore used OnDeliverMessage at some point during development. Nevertheless I do not remember what the problem was... hmm. Anyway, the script works fine for me by using the OnDeliverMessage event.
Re: HOWTO: Using SpamAssassin with hMailServer
In advance apologies for the n00b questions. I have had a good read through this thread and its all still about as clear as mud...!!
I have opted for the somewhat easier approach, or so i thought, of using the pre-compliled executables for spamassassin the source forge SpamAssassin-3.2.3.5-win32.zip version for command line win32. Im running
hmail 4.4 B270.
I have used your script shelby and its just not really doing a great deal. To check i have done this...
1: i assume you copy the script to the end of the: EventHandlers.vbs
2: In hmail>settings>advanced i have 'active' and tghe syntax checks fine.
3: I have not added spamassassin into environment/PATH location instead i have called it by its location on the line. "Const SAHI_default_scan_command_line = "%comspec% /c c:\spamassassin\spamc.exe -E -s 512000"
" minus the quotes.
4: I have uncommented thus:
Sub OnDeliverMessage(oMessage)
SAHI_processMessage oMessage
End Sub
5: I have set the learn line as follows:
Const SAHI_learn_command_line = "%comspec% /c c:\spamassassin\sa-learn.exe --"
I just wondered if it was ok for someone to post a: "this is how its done" with the pre-copiled bundle, start to finish, or a quicker one just point me in the general direction so i can get SA implemented ion my 2k3 box.
I know its a big ask but am sure it would help this thread no end,
Regards,
Mike.
I have opted for the somewhat easier approach, or so i thought, of using the pre-compliled executables for spamassassin the source forge SpamAssassin-3.2.3.5-win32.zip version for command line win32. Im running
hmail 4.4 B270.
I have used your script shelby and its just not really doing a great deal. To check i have done this...
1: i assume you copy the script to the end of the: EventHandlers.vbs
2: In hmail>settings>advanced i have 'active' and tghe syntax checks fine.
3: I have not added spamassassin into environment/PATH location instead i have called it by its location on the line. "Const SAHI_default_scan_command_line = "%comspec% /c c:\spamassassin\spamc.exe -E -s 512000"
" minus the quotes.
4: I have uncommented thus:
Sub OnDeliverMessage(oMessage)
SAHI_processMessage oMessage
End Sub
5: I have set the learn line as follows:
Const SAHI_learn_command_line = "%comspec% /c c:\spamassassin\sa-learn.exe --"
I just wondered if it was ok for someone to post a: "this is how its done" with the pre-copiled bundle, start to finish, or a quicker one just point me in the general direction so i can get SA implemented ion my 2k3 box.
I know its a big ask but am sure it would help this thread no end,
Regards,
Mike.
Re: HOWTO: Using SpamAssassin with hMailServer
Ah well, let me see through my crystal ball...and its just not really doing a great deal.
Is there a chance that you'll be more specific? Turn on SAHI logging?
Re: HOWTO: Using SpamAssassin with hMailServer
Hey shelby,
Thanks for the reply and apologies for the inconcise post, it was a bit of a rush at the end of my day... It takes another person to read your question for you then to really realise what you missed and i missed out a fair bit.
Ok so the logging is showing:
3496 "2008-05-09 11:07:23.186" "34090 | <266E3068F62AB04287C5E8332226E6841A23BA@dellpipe26.Charterhousekent.co.uk> | ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
2364 "2008-05-09 11:22:42.202" "34100 | <000301c8b197$8e1a85a0$c0a80168@Claudio> | ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
all logs show this SAHI_scan: error found
To remove any of my .exe paranoias I have tried it with spamc and spamassassin with no difference via the commands:
Const SAHI_default_scan_command_line = "%comspec% /c c:\spamassassin\spamassassin -e"
Const SAHI_default_scan_command_line = "%comspec% /c c:\spamassassin\spamc -E -s 512000"
Thanks for your time on this, I know how frustrating it can be trying to explain how to get it up an running. As soon as i do get mine running there is a bunch of posts asking for a 'how to guide' on 2k3>SA>Hmail4.4[B270] on the forum so i'll get that all answered for everyone.
Thanks again,
Mike.
Thanks for the reply and apologies for the inconcise post, it was a bit of a rush at the end of my day... It takes another person to read your question for you then to really realise what you missed and i missed out a fair bit.
Ok so the logging is showing:
3496 "2008-05-09 11:07:23.186" "34090 | <266E3068F62AB04287C5E8332226E6841A23BA@dellpipe26.Charterhousekent.co.uk> | ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
2364 "2008-05-09 11:22:42.202" "34100 | <000301c8b197$8e1a85a0$c0a80168@Claudio> | ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
all logs show this SAHI_scan: error found
To remove any of my .exe paranoias I have tried it with spamc and spamassassin with no difference via the commands:
Const SAHI_default_scan_command_line = "%comspec% /c c:\spamassassin\spamassassin -e"
Const SAHI_default_scan_command_line = "%comspec% /c c:\spamassassin\spamc -E -s 512000"
Thanks for your time on this, I know how frustrating it can be trying to explain how to get it up an running. As soon as i do get mine running there is a bunch of posts asking for a 'how to guide' on 2k3>SA>Hmail4.4[B270] on the forum so i'll get that all answered for everyone.
Thanks again,
Mike.
Re: HOWTO: Using SpamAssassin with hMailServer
I have also just checked my mailboxes in thunderbird and they are set up as IMAP, just so i can keep all the mail on the server, I check it from all over with squirrelmail which is installed on the box. Not too sure if this impacts the situation but thought I'd give the heads up. As the test for the mail i'm using the thunderbird 'redirect' and 'redirecting' from one local account to another.
bests,
Mike.
bests,
Mike.
Re: HOWTO: Using SpamAssassin with hMailServer
Mike, please search the script and change the logging setting to the following line (if it's not at all):
This should create the most extensive amount of logging. Please do another test and post the complete set of logging messages for one test. Each resulting line of log contains of a prefix eg.
Search for all lines that do contain the same message handle (in the above example: <12449399.76971464@spite.com>) and post it here.
I am not quite sure, but you may have to add the path to spamassassin to your path.
Code: Select all
Const SAHI_trace_level = 8
Code: Select all
"2008-05-09 13:01:15.443" "176192 | <12449399.76971464@spite.com> | INFORMATION(7) | ...
I am not quite sure, but you may have to add the path to spamassassin to your path.
Re: HOWTO: Using SpamAssassin with hMailServer
Shelby,
Ok I have upped the trace level from 4 to 8 and it now reads:
2708 "2008-05-09 13:50:21.125" "34139 | <021201c8b19b$fadf13f0$c0a80121@Kennith> | ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
Interestingly (or not) when I redirect a mail to the test account I get a log entry but when I just send it a mail I don't. Also the 'sent' mail has its headers altered by spamassassin: (so it does seem to be running without the PATH entry)
X-Spam_Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on [SERVERNAME]
X-Spam-Status: No, score=0.2 required=6.3 tests=ALL_TRUSTED,HTML_MESSAGE, MIME_HTML_ONLY shortcircuit=no autolearn=no version=3.2.3
The only (and maybe problematic) difference is that the 1 spam e-mail I have that I am testing the redirect with, had a previous edited header and has the appended line: X-Spam-Check-Status: Checked on incoming
Until i get a new spam message this is the only one i have.
Hope that helps for now, thanks again matey,
Mike.
Ok I have upped the trace level from 4 to 8 and it now reads:
2708 "2008-05-09 13:50:21.125" "34139 | <021201c8b19b$fadf13f0$c0a80121@Kennith> | ALERT(2) | SAHI_scan: Error found: Resulting file is empty, see previous messages for probably reported error"
Interestingly (or not) when I redirect a mail to the test account I get a log entry but when I just send it a mail I don't. Also the 'sent' mail has its headers altered by spamassassin: (so it does seem to be running without the PATH entry)
X-Spam_Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on [SERVERNAME]
X-Spam-Status: No, score=0.2 required=6.3 tests=ALL_TRUSTED,HTML_MESSAGE, MIME_HTML_ONLY shortcircuit=no autolearn=no version=3.2.3
The only (and maybe problematic) difference is that the 1 spam e-mail I have that I am testing the redirect with, had a previous edited header and has the appended line: X-Spam-Check-Status: Checked on incoming
Until i get a new spam message this is the only one i have.
Hope that helps for now, thanks again matey,
Mike.
Re: HOWTO: Using SpamAssassin with hMailServer
I just checked another account on the server and that usually gets hammered by spam i found a spam e-mail in it and it has this header:
Return-Path: <ouuxmkcld@telesp.net.br>
X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on kirsten.browtop
X-Spam-Level: *
X-Spam-Status: No, score=1.7 required=6.3 tests=HTML_MESSAGE,MIME_HTML_ONLY, RDNS_NONE shortcircuit=no autolearn=no version=3.2.3
So it does seem to be running, i think... I just cant find the log entry for that as before i ran my latest local tests here i flushed the log...!! (dickhead, i know)
Mike.
Return-Path: <ouuxmkcld@telesp.net.br>
X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on kirsten.browtop
X-Spam-Level: *
X-Spam-Status: No, score=1.7 required=6.3 tests=HTML_MESSAGE,MIME_HTML_ONLY, RDNS_NONE shortcircuit=no autolearn=no version=3.2.3
So it does seem to be running, i think... I just cant find the log entry for that as before i ran my latest local tests here i flushed the log...!! (dickhead, i know)
Mike.
Re: HOWTO: Using SpamAssassin with hMailServer
Mike, I need all the log lines for this specific mail. This means: More than one. Many. About 10 to 20. Not the whole log. The above was just a sample how you could identify a log line. I need something like:
I hope it doesn't sound rude, but did you configure all the other options in the script header appropriatly? Please PM me your configuration from the script headers.
Code: Select all
840 "2008-05-05 05:21:05.547" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | INFORMATION(7) | SAHI_Version: 1.2"
840 "2008-05-05 05:21:05.562" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | NOTICE(6) | SAHI_processMessage: From: "Lavonne Pagan" <frizzesyfax1@yahoo.it> To: <mail@shelby.de> Subject: Der beeeeste Preeeeis im Web! Viiiaaaagra - 0.88 EURO Filename: C:\Programme\hMailServer\Data\{25DC3B0D-9FDB-4C47-A813-CC9951868C1B}.eml"
840 "2008-05-05 05:21:05.562" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_isOutgoing: received=from [88.220.176.70] (unknown [88.220.176.70]) by dd14934.kasserver.com (Postfix) with ESMTP id 4126D101080C1 for <mail@shelby.de>; Mon, 5 May 2008 05:18:34 +0200 (CEST)"
840 "2008-05-05 05:21:05.562" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | INFORMATION(7) | SAHI_isOutgoing: Incoming mail detected"
840 "2008-05-05 05:21:05.562" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_doScan: Spam check enabled on incoming mails"
840 "2008-05-05 05:21:05.562" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_scan: Checking mail for spam"
840 "2008-05-05 05:21:05.562" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_executeCommand: command=%comspec% /c spamassassin -e < "C:\Programme\hMailServer\Data\{25DC3B0D-9FDB-4C47-A813-CC9951868C1B}.eml" > "C:\Programme\hMailServer\Data\{25DC3B0D-9FDB-4C47-A813-CC9951868C1B}.eml.tmp""
840 "2008-05-05 05:21:20.265" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_executeCommand: command returned with 1"
840 "2008-05-05 05:21:20.265" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | INFORMATION(7) | SAHI_scan: Spam found"
840 "2008-05-05 05:21:20.265" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_scan: Replacing mail file with checked result file"
840 "2008-05-05 05:21:20.265" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_isAboveDiscardScore: discard_score: ************ X-Spam-Level: ***************** X-Spam-Status: Yes, score=17.2 required=5.0 tests=BAYES_99,HTML_MESSAGE, OUTLOOK_3416,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_XBL,RDNS_NONE,URIBL_AB_SURBL, URIBL_JP_SURBL,URIBL_OB_SURBL,URIBL_SBL,URIBL_SC_SURBL autolearn=spam version=3.2.2"
840 "2008-05-05 05:21:20.265" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | DEBUG(8) | SAHI_isAboveDiscardScore: Mail is marked to be discarded"
840 "2008-05-05 05:21:20.265" "174681 | <01c8ae67$142ae880$46b0dc58@frizzesyfax1> | NOTICE(6) | SAHI_processMessage: Mail flagged as spam - discarding mail because it is above discard score of 12"
Re: HOWTO: Using SpamAssassin with hMailServer
Does any body knows, where I can find "6.Really good how to install SpamAssassin tutorial"? I can't find the tutorial on http://www.openhandhome.com/howtosa300.html
Avoid double-checking emails forwarded to local account
Hi,
Is there a way to change the line so that I can avoid having forwarded mails to local accounts double-checked with spamassassin? Right now, its set so mails originating from the local lan are recognized, i.e. 192.168.xxx. Forwarded mails originate from localhost, though.
p.s. Thanks to everyone involved in HMS, this is great software!
Is there a way to change the
Code: Select all
Const SAHI_domain_received_header
p.s. Thanks to everyone involved in HMS, this is great software!
Re: HOWTO: Using SpamAssassin with hMailServer
Hi again,
I haven't figured out a solution to my problem from the above post, and already I have another question:
How can I control into which directory the Bayes data is written to? I have the SAWin32 executables (spamc.exe, spamd.exe, sa-learn.exe) and have spamd installed as Windows service which starts under 'LocalSystem' account.
Now, there are several '.spamassassin' directories in the 'Documents and Settings/[USER]' directory tree, were [USER] is all the local users plus NetworkService and LocalService. When I first installed SA and Shelby's script all the Bayes data was written into the 'Documents and Settings/NetworkService/.spamassin' directory, that is data from the SA auto-learning AND the data from when I sent emails from my email client to the learn_mailboxes configured in Shelby's script.
Now, and I am really confused about this: After rebooting the computer the auto-learn data gets written into another directory (one of the local users) and the data from the learn_mailboxes feature in Shelby's script (which uses sa-learn.exe) gets written into yet another directory: 'Docu...Settings/LocalService/.spamassassin'
I am not sure if this is the right forum for this question, but maybe someone has already had this problem, too, and can help.
Thanks!
I haven't figured out a solution to my problem from the above post, and already I have another question:
How can I control into which directory the Bayes data is written to? I have the SAWin32 executables (spamc.exe, spamd.exe, sa-learn.exe) and have spamd installed as Windows service which starts under 'LocalSystem' account.
Now, there are several '.spamassassin' directories in the 'Documents and Settings/[USER]' directory tree, were [USER] is all the local users plus NetworkService and LocalService. When I first installed SA and Shelby's script all the Bayes data was written into the 'Documents and Settings/NetworkService/.spamassin' directory, that is data from the SA auto-learning AND the data from when I sent emails from my email client to the learn_mailboxes configured in Shelby's script.
Now, and I am really confused about this: After rebooting the computer the auto-learn data gets written into another directory (one of the local users) and the data from the learn_mailboxes feature in Shelby's script (which uses sa-learn.exe) gets written into yet another directory: 'Docu...Settings/LocalService/.spamassassin'
I am not sure if this is the right forum for this question, but maybe someone has already had this problem, too, and can help.
Thanks!
Re: HOWTO: Using SpamAssassin with hMailServer V4
After a bit of research and getting familiar with SpamAssassin I figured out how to solve my problems from above two posts (these were really SpamAssassin related and have nothing to do with hMailServer or Shelby's Script):
Avoid have SpamAssassin double-check internally forwarded messages:
This can be done via a header rule in local.cf to identify the unique header line of a locally forwarded mail and then shortcircuiting the other SA checks.
example lines to add to local.cf:
for help see
http://spamassassin.apache.org/full/3.2 ... rcuit.html and
http://www.troubleshooters.com/codecorn ... erlreg.htm
I do this because I have all email from my several email accounts which is classified as spam forwarded to an extra account, e.g. SPAM@domain.com. It is really fruitless to have these messages spam-checked a second time.
Define a directory for the Bayes data:
Also in local.cf add following lines:
or whatever suits you better.
Avoid have SpamAssassin double-check internally forwarded messages:
This can be done via a header rule in local.cf to identify the unique header line of a locally forwarded mail and then shortcircuiting the other SA checks.
example lines to add to local.cf:
Code: Select all
header INTERNAL_FORWARD Received =~ /[RegularExpression]/
shortcircuit INTERNAL_FORWARD on
priority INTERNAL_FORWARD -500
score INTERNAL_FORWARD 7
tflags INTERNAL_FORWARD noautolearn
http://spamassassin.apache.org/full/3.2 ... rcuit.html and
http://www.troubleshooters.com/codecorn ... erlreg.htm
I do this because I have all email from my several email accounts which is classified as spam forwarded to an extra account, e.g. SPAM@domain.com. It is really fruitless to have these messages spam-checked a second time.
Define a directory for the Bayes data:
Also in local.cf add following lines:
Code: Select all
bayes_path E:\Bayes\bayes
auto_whitelist_path E:\Bayes\auto-whitelist
Re: HOWTO: Using SpamAssassin with hMailServer V4
Hi,
I'm trying to find a tutorial for install like is in the first message if this topic, but some links don't exist anymore. Please, if someone can show me any tutorial about how to install it, I will thjank you.
Regards.
I'm trying to find a tutorial for install like is in the first message if this topic, but some links don't exist anymore. Please, if someone can show me any tutorial about how to install it, I will thjank you.
Regards.
Shelby's Script works with hMailServer V5 too
Thank you Shelby for your wonderful script.
I've been using it about three weeks with hMailServer 5.3.2-B1769 and SpamAssassin 3.3.1 on Windows Server 2008 SP2 x64, without problem.
I've been using it about three weeks with hMailServer 5.3.2-B1769 and SpamAssassin 3.3.1 on Windows Server 2008 SP2 x64, without problem.
Re: HOWTO: Using SpamAssassin with hMailServer V4
HELP...this is so confusing...Is SAwin32 the easiest way? I think i want to use it but what do i do the links to the scripts ealier in this post don't work after reading all this my head is spinning can someone please give me a updated breakdown of implementing SAwin32??? PLEASE...I have never used SA at all...AKA noob, somewhat.
- tBB
- Senior user
- Posts: 268
- Joined: 2009-04-17 18:10
- Location: The land of Beer and Sauerkraut!
- Contact:
Re: HOWTO: Using SpamAssassin with hMailServer V4
SAWin32 is not longer being developed. Better use 'SpamAssassin for Windows' from http://www.jam-software.com/spamassassin/ Version 1.1 equals SA 3.3.1
Best regards,
Nico
Best regards,
Nico
Re: HOWTO: Using SpamAssassin with hMailServer V4
What would be the easist implementation of this? Is there a script or would it just be a command line thing?
- tBB
- Senior user
- Posts: 268
- Joined: 2009-04-17 18:10
- Location: The land of Beer and Sauerkraut!
- Contact:
Re: HOWTO: Using SpamAssassin with hMailServer V4
hMS natively supports SpamAssassin (SpamD) See http://www.hmailserver.com/documentatio ... e_antispammattfox27 wrote:What would be the easist implementation of this? Is there a script or would it just be a command line thing?
Note that SpamD/Win32 has a small memory leak so using Toom's SpamDloaderService (http://www.tooms.dk/software/spamdloade ... efault.asp) is a good idea.
Best regards,
Nico
Re: HOWTO: Using SpamAssassin with hMailServer V4
Would this be an easier implementation?SAWin32 is not longer being developed. Better use 'SpamAssassin for Windows' from http://www.jam-software.com/spamassassin/ Version 1.1 equals SA 3.3.1
- tBB
- Senior user
- Posts: 268
- Joined: 2009-04-17 18:10
- Location: The land of Beer and Sauerkraut!
- Contact:
Re: HOWTO: Using SpamAssassin with hMailServer V4
Easier than what?mattfox27 wrote:Would this be an easier implementation?
The SA for Windows I've mentioned has a setup which installs SA and downloads the latest rules. Then you just have to edit the \etc\spamassassin\local.cf configuration file to suit your needs, start SpamD and enable the support in hMS. Tooms SpamDloaderService only checks if SpamD runs and if not, restarts it. However, SpamAssassin isn't a out-of-the box solution in any case. If you want it to deliver good results then you have to get at least a little bit familiar with it.
Best regards,
Nico
Re: HOWTO: Using SpamAssassin with hMailServer V4
So i downloaded and installed the jam-software version but it fails to start what are the basic parameters that need to be in conf file to get it to run?
Thanks for your help
Thanks for your help
- tBB
- Senior user
- Posts: 268
- Joined: 2009-04-17 18:10
- Location: The land of Beer and Sauerkraut!
- Contact:
Re: HOWTO: Using SpamAssassin with hMailServer V4
What fails to start? SpamD? It should tell you in it's window why it failed to start. There is nothing in the local.cf config file that could cause SpamD to not start. There you should adjust the trusted_networks entry to match your LAN/whatever IP's and configure the 'shortcircuit' parameters to save CPU time but all settings are well documented inside the config file(s).mattfox27 wrote:So i downloaded and installed the jam-software version but it fails to start what are the basic parameters that need to be in conf file to get it to run?
As I've mentioned, SpamAssassin is a quite complex tool and not exactly suited to beginners but once correctly configured a mighty weapon against spam. Please have a look at http://www.jam-software.com/spamassassin/manual.shtml and http://wiki.apache.org/spamassassin/ Once you understood the concept you'll know what you need to configure, how to train the Bayesian database and so on. If you have further questions regarding the functionality of SA, this is probably the better place to ask: http://wiki.apache.org/spamassassin/MailingLists (but read the notes).
Best regards,
Nico
Re: HOWTO: Using SpamAssassin with hMailServer V4
I got it to work...i think. Im using the tooms.dk windows service software...is that a good approach? Does anyone have experience using that program? It seems to be working but it won't allow updates. DO i need to enable updates in conf file? I know i need to read the manuals and all that and i'am doing so i was just looking for some quick setup info so sorry if im being a pain