Microsoft Exchange Event Sink Doesn't Save File in Badmail Folder

I have created an Exchange event sink on my SBS server (Microsoft Small Business Server 2003) and registered/installed it. I want it to catch any incoming message with the subject line "AccuWeather.com Alert Forecast" and dump it into the badmail folder instead of delivering it. I am setting the message status field to 3 to cause the incoming message to be dumped into the badmail folder instead of being delivered, but the message never shows up in the badmail folder. I know the message is being intercepted because it doesn't ever reach my inbox.

I downloaded the smtpreg.vbs script from the Microsoft web site.

Why is this successfully keeping the message from being delivered, but not putting the message in my badmail folder? I have checked to make sure that the badmail path in the messages tab of the SMTP properties in Exchange System Manager does match the badmail path I'm looking in.

Thanks in advance.

Here's the code I'm using for the event sink:
 
-------------- cut here ------------------------
<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 
	Set envFlds = Msg.EnvelopeFields 
 
	If Msg.Subject = "" Or Len(Msg.Subject) < 30 Then 
		iFound = 0 
	Else 
		iFound = Instr(1, Msg.Subject, "AccuWeather.com Alert Forecast", 1) 
	End If
 
	If iFound > 0 Then 
		envFlds ("http://schemas.microsoft.com/cdo/smtpenvelope/messagestatus") = 3 
		envFlds.Update
		EventStatus = 1
	End If 
End Sub 
 
</SCRIPT>
-------------- cut here ------------------------
 
And here's the batch file I'm using to install it:
-------------- cut here ------------------------
@Echo Off
 
REM *********** The following 2 lines install the Event Sink to log SMTP Messages ***********
Cscript smtpreg.vbs /add 1 onarrival SMTPMessageCheck CDO.SS_SMTPOnArrivalSink "mail from=*"
Cscript smtpreg.vbs /setprop 1 onarrival SMTPMessageCheck Sink ScriptName "C:\EventSink\SMTPMsgCheck.vbs"
-------------- cut here ------------------------

Open in new window

moaneyeAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
moaneyeConnect With a Mentor Author Commented:
I've managed to solve this problem myself. Instead of depending on the badmail folder, I ended up saving the HTMLBody portion of the IMessage object to a file via FileSystem objects. I've attached the final code. This works really well, and saves me the step of having to do an EML to HTML conversion. The HTMLBody property of the IMessage object is really cool.

Thanks for your time and input.
<SCRIPT LANGUAGE="VBScript"> 
 
Sub IEventIsCacheable_IsCacheable() 
	'To implement the interface, and return S_OK implicitly 
End Sub
 
Sub ISMTPOnArrival_OnArrival(ByVal Msg, EventStatus) 
	Const cdoRunNextSink = 0
	Const cdoSkipNextSink = 1
	Const fsoForReading = 1
	Const fsoForWriting = 2
	Const fsoForAppending = 8
 
	Dim envFlds 
	Dim colAttachs 
	Dim iFound 
	Dim sFilename
	Dim objFSO 
	Dim objTextFile 
	Dim objFile
 
	Set envFlds = Msg.EnvelopeFields 
 
	If Msg.Subject = "" Or Len(Msg.Subject) < 30 Then 
		iFound = 0 
	Else 
		iFound = Instr(1, Msg.Subject, "AccuWeather.com Alert Forecast", 1) ' First position of the phrase AccuWeather.com Alert Forecast 
	End If
 
	If iFound > 0 Then 
		' format date
		strDate = Year(Now) & Month(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now)
 
		' save message to disk
	
		sFilename = "C:\EventSink\Hold\lastmessage." & strDate & ".htm"
   
 
		Set objFSO = CreateObject("Scripting.FileSystemObject")
 
		Set objFile = objFSO.CreateTextFile(sFilename)
		set objFile = nothing
		Set objTextFile = objFSO.OpenTextFile _
			(sFilename, fsoForAppending, True)
 
		objTextFile.Write(Msg.HTMLBody)
		objTextFile.Close
 
		'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 
 
		' allow other sinks to run
		EventStatus = cdoRunNextSink
	End If 
End Sub 
 
</SCRIPT>

Open in new window

0
 
moaneyeAuthor Commented:
Maybe more points will help?
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Seems like a rather complex way to handle this... but the reason it's not working is that you're missing a "Next" command after your first "End If".

Jeff
TechSoEasy
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
moaneyeAuthor Commented:
Am I missing something? There is no "for" loop in this code. Why would I need a "next" statement anywhere?

Also, if this is a complex way to handle this, what would be an easier way?

Thanks.
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Actually... sorry, I missed the fact that you are also missing a "for" command... because you have an "If iFound > 0 Then", but you have no way for iFound to have a value greater than 0.

I'm assuming that you used the code in this KB article as a reference?
http://support.microsoft.com/kb/313404

Since the script isn't able to assign a value greater than 0 to iFound, your last "If" statement couldn't ever apply.

What would be an easier way?  Well, I use Trend Micro Client/Server/Messaging security on all SBS's I deploy, and that suite has built-in email content filtering.  If your AV does as well, it'd be easier to use that since it's already scanning each message... no need for a second sink.

Jeff
TechSoEasy
0
 
moaneyeAuthor Commented:
Yes, I did use the KB article as the base from which I built the code, but made some modifications. Actually, iFound is going to be greater than 0 any time the sting "AccuWeather.com Alert Forecast" is in the subject line. That's what driggers the code inside the second "if" statement.
Yes, I could use a content filtering/e-mail virus scanning program if I was just trying to scan my e-mails for viruses or stop spam. But that's not what I'm doing. In this case, I'm working for a client who hired me to write custom code to catch any message with the string "AccuWeather.com Alert Forecast" in the subject line and save it to disk, whereupon I have to convert the HTML content of the message to an image in JPEG/JPG format and save it to another server where it is loaded up into an unattended kiosk program. This all has to work automatically, with no human intervention.
Thanks.
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
Ahhh... why don't they just have it go to a Public Folder then?  You can then write a rule that would run whatever program/script you want afterwards to handle the message?  That way everything is handled within Exchange rather than having to deal with a .msg file within an NTFS folder.

Just a thought...

Jeff
TechSoEasy
0
 
Jeffrey Kane - TechSoEasyPrincipal ConsultantCommented:
But then again, you could also just contact Accuweather.com and use their API to deliver the content to the kiosk terminal.  (http://www.accuweather.com/api.asp) or their downloadable tools:  http://www.accuweather.com/downloadcenter.asp

Because the way you are doing it may violate their copyright.

Jeff
TechSoEasy
0
 
moaneyeAuthor Commented:
I suppose there are many ways to skin this cat, however, personally I'd rather work on a .eml file (my script saves it as that, instead of a .msg file) in an NTFS folder than dealing with a public folder in outlook. Either way, I have to write a script, either as an event sink (like I'm doing now) or as a script triggered by a rule, and even if I write a script triggered by a rule, I still have to dump the message into a file for processing by the HTML to JPG conversion program.

As for copyright, my understanding is that my client has already inquired about that issue and has been given permission to do this internally to their company, which is what they are doing. They are a pretty major international mining company and are typically very careful about such issues.
0
All Courses

From novice to tech pro — start learning today.