?
Solved

SMTP Transport Sink Event Problem

Posted on 2005-05-08
3
Medium Priority
?
772 Views
Last Modified: 2007-12-19
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.
0
Comment
Question by:GeoffWhite
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Vahik
ID: 13956845
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???
0
 

Author Comment

by:GeoffWhite
ID: 13957352
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")
0
 
LVL 26

Accepted Solution

by:
Vahik earned 1000 total points
ID: 13959702
sorry i could not help u with scripting....u could ask the question in the VB section...
if this did not work the way u wanted it maybe u could use ur antispam software...
some Antispam softwares could do this job...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The main intent of this article is to make you aware of ‘Exchange fail to mount’ error, its effects, causes, and solution.
Here in this article, you will get a step by step guidance on how to restore an Exchange database to a recovery database. Get a brief on Recovery Database and how it can be used to restore Exchange database in this section!
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question