I think I found a bug in VBScript / SMTP EventSinks - please help

Discussion in 'Scripting' started by Chris, Feb 26, 2004.

  1. Chris

    Chris Guest

    System: Win2K3 server, running the default Microsoft SMTP service. The serve
    is forwarding mail to an internal email server

    Problem: I am trying to get a vbscript running that will run spamassassin on all email coming into my network. The script below runs, and creates a spamtestin.txt file. However, the script never calls the batch file spamassassin.bat. Does anyone know why not? This script runs fine from a command prompt, BTW

    I installed spamassassin using the instructions from here
    http://www.openhandhome.com/howtosa260.htm

    All my spamassassin tests are 100% successful. I then downloaded
    recommended vbscript to integrate spamassassin with the SMTP service
    via something called an eventsink

    When I enable the spamfilter.vbs eventsink, email still flows jus
    fine. However, spamassassin never runs

    Can anyone assist me in getting the code below to actually run o
    every email

    <SCRIPT LANGUAGE="VBSCRIPT"
    On Error Resume Nex

    ' Declare Windows 2000/2003 SMTP Transport Event Sink constant
    Const cdoRunNextSink =
    Const cdoSkipRemainingSinks =
    Const cdoStatAbortDelivery =
    Const cdoStatBadMail =

    ' Declare ADO constant
    Const adSaveCreateOverWrite =

    ' paths to folders we will be usin
    Const TEST_PATH = "c:\TEST\
    Const SPAM_PATH = "c:\test\spam_final\
    Const NONSPAM_PATH = "c:\test\NONSPAM_FINAL\

    Sub ISMTPOnArrival_OnArrival(ByVal objMessage, EventStatus

    'Start up Error Checking (so that we can promptly ignore it
    On Error Resume Nex

    ' Declare variable
    Dim strTestEmai
    Dim objFields
    Dim objStream
    Dim iCount
    Dim listRnd
    Dim iRnd
    Dim strRando
    Dim oShel
    Dim objFileSyste
    Dim strMessag
    Dim ts
    Dim


    ' Get fields collection of messag
    Set objFields = objMessage.EnvelopeFields

    ' Process messag
    With objMessag

    ' Get message as strea
    Set objStream = .GetStrea

    ' Save message as stream to file
    objStream.SaveToFile (TEST_PATH & "spamtestin.txt")
    adSaveCreateOverWrit
    End Wit

    'spamtest file now exists, so we should now run spamassassi
    against it and have it output a fil
    ------- Here is the broken part of the script ----------------
    Set oShell = wscript.CreateObject("WScript.Shell"
    comm = "e:\perl\bin\spamassassin.bat < c:\TEST\spamtestin.txt > c:\TEST\spamtestout.txt
    oShell.Run com
    ----------------------------------------------------------------------

    'now open up the spamtestout.txt file and see if that is spam (se
    if it contains "X-Spam-Status: Yes
    'if it is spam, then copy spamtestin.txt to a randomly named tex
    file in the SPAM_PAT
    'if it is not spam, then copy spamtestin.txt to a randomly name
    text file in the NONSPAM_PAT
    'then later run bat scripts to learn on those directories, an
    then del the files in there after learnin

    Set objFileSystem = CreateObject("Scripting.FileSystemObject"

    'open up the fil
    Set f = objFileSystem.GetFile(TEST_PATH & "spamtestout.txt"
    Set ts = f.OpenAsTextStream(1,-2
    strMessage = ts.ReadAl
    ts.Clos

    If InStr(1, strMessage, "X-Spam-Status: Yes", 1) The
    'if in here, then we will add a flag to the messag
    subjec
    objMessage.Subject = "*****SPAM*****" & objMessage.Subjec
    objMessage.DataSource.Sav
    'the message is still getting sent to the user, so kee
    checking sink
    EventStatus = cdoRunNextSin
    End I


    ' Clean up the mess we have mad
    Set objFileSystem = Nothin
    Set objStream = Nothin
    Set objFields = Nothin
    Set oShell = Nothin
    Set f = Nothin
    Set ts = Nothin

    End Su
    </SCRIPT>
     
    Chris, Feb 26, 2004
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.