Link to home
Start Free TrialLog in
Avatar of GeoffWhite
GeoffWhite

asked on

SMTP Transport Sink Event Problem

I am trying to make a sink that will nuke any emails with a small zip file attached.  I have got my users pretty well trained, but sooner or later one is going to do something stupid.

I have written a vbs to do the job (mostly pinched from MS) but I can't seem to get it to fire at all!?  I use the standard MS script to register the event and I says everything is ok but nothing happens.  I have some diagnostic code in there but it does not produce anything.

And yes, I have restarted the Default SMTP server.

The reg code is:
cscript smtpreg.vbs /add 1 onarrival NoSmallZips CDO.SS_SMTPOnArrivalSink "rcpt to=*"
cscript smtpreg.vbs /setprop 1 onarrival NoSmallZips Sink ScriptName "c:\sinkevents\nosmallzips.vbs"

The script is:

<SCRIPT LANGUAGE="VBScript">

Sub IEventIsCacheable_IsCacheable()
      'To implement the interface, and return S_OK implicitly
End Sub

Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus)
      Dim envFlds
      Dim colAttachs
      Dim iFound
      Dim iSize
      
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set wFile = fso.OpenTextFile("c:\nozip_Log.txt", 8, True)
      wfile.WriteLine ("Event Sink Fired at " & Now)

      Set envFlds = Msg.EnvelopeFields
      Set colAttachs = Msg.Attachments

      Wfile.writeline ("Mail from :" & Msg.From)
      Wfile.writeline ("Mail Subject :" & Msg.Subject)


      If Msg.Subject="Zip Test" Then

            For Each oAttach in colAttachs
                  Wfile.writeline ("Filename: " & oAttach.FileName)
                  If InStrRev(oAttach.FileName, ".vbs",-1, 1) = (Len(oAttach.FileName)-3) Then
                        iSize=oAttach.Fields(&H0E200003) 'CdoPR_ATTACH_SIZE
                        Wfile.writeline ("Size :" & iSize)
                        if iSize < 100000  Then
                              iFound = 1
                        End If
                  End If
            Next

            If iFound > 0 Then
                  'Do not deliver, place message in the Badmail directory.
                  envFlds ("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus") = 3
                  envFlds.Update  'Commit the changes of the message status 'Skip remain event sinks
                  EventStatus = 1
            End If
      End if
End Sub

</SCRIPT>

I do not get anything at all in the log file.

Please tell me I have done something stupid here.
Avatar of Vahik
Vahik

http://support.microsoft.com/?kbid=258224
cscript smtpreg.vbs /enum  use this command to see if the event sink i sregistered at all
i am sure ur event sink is in a directory...in c: drive called sinkevents containing a file named nosmallzip.vbs.....

cscript smtpreg.vbs /add 1 onarrival NoSmallZips CDO.SS_SMTPOnArrivalSink "rcpt to=*"
cscript smtpreg.vbs /setprop 1 onarrival NoSmallZips Sink ScriptName "c:\sinkevents\nosmallzips.vbs"
and this is the instruction in ur .bat file??  then if enum showed it registered then u should not have any problem...ask one some one from outside to send an attachment that matches ur filter and see what happens???
Avatar of GeoffWhite

ASKER

Ah yes, it is a SMTP event isn't it.  When I send from an non-exchange client the event fires.

Only problem is it stops running at the point where I am trying to get the size of the attachment using:
     iSize=oAttach.Fields(&H0E200003)
or iSize=oAttach.Fields.Item(&H0E200003).Value
or iSize=oAttach.Size

How the hell do you get the size of an attachment anyway?!!

It only seems to iterate the first attachment also (I guess it bombs before the "next")
ASKER CERTIFIED SOLUTION
Avatar of Vahik
Vahik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial