Solved

VBS &/or Batch File - SpamAssassin as Mailenable Pickup event

Posted on 2013-01-14
16
954 Views
Last Modified: 2013-02-01
Dear Experts,

Background:

I run an Email Server using MailEnable (on a W2008r2 Web Box).

To reduce the amount of Spam, I am using Spam Assassin.

Spam Assassin needs various switches to be set, and will only seem to run properly if I submit the command thus:
c:\SpamA\spamassassin.exe -e c:\DATA\MAILEN~1\QUEUES\QUEUENAME\INBOUND\MESSAGES\FILENAME.MAI > c:\DATA\MAILEN~1\QUEUES\QUEUENAME\INBOUND\MESSAGES\FILENAME.MAIL

Open in new window


MailEnable can only run the "Pickup Event" as:
C:\SpamA\spamassassin.exe FILENAME QUEUENAME

Open in new window


So, I introduced a Batch File to do the processing. MailEnable's Pickup event is now Filter.CMD, which builds and runs the Spam Assassin Command.

The above works, but I now need to do more processing of the email.

Spam Assassin is marking legitimate email as SPAM when one of my users connects from a Mobile or Coffee Shop WiFi connection, as SpamAssassin sees these connections as Spammy.

My Work around:

To do the extra processing, I wanted to use VBS rather than CMD (as I can do VBS, and it should have the power to do what I need).

The problem I face is that CMD will run and wait for SpamAssassin to finish, whereas (even with the WAIT option) VBS will not. Running:
WshShell.Run SpamAssassinCommand, 1, True
WScript.Echo("This is too early")

Open in new window

... brings up the output box "This is too early" before the SpamAssassin Command has finished.

Any pointers as to what I am doing wrong, or how I can make VBS wait for Spam Assassin to finish before moving on would be appreciated.

GH
0
Comment
Question by:G_H
  • 8
  • 7
16 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
Comment Utility
Hi G_H - I can't help on this one.  But my experience using Spam Assassin with both Mail Enable and Smartermail was not so great.  I gave up on Spam Assassin altogether and went right to g-apps and now everybody is happy.    I hope this works for you.
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
instead of running the spam assassin command directly, run CMD.exe followed with the spam assassin command
0
 
LVL 11

Author Comment

by:G_H
Comment Utility
@padas
Thanks for the suggestion, I will take a look for the "next gen" but I am stuck here for now...

@ailimark
I have just tried this:
Set WshShell = WScript.CreateObject("WScript.Shell")
	intReturn = WshShell.Run("cmd.exe ""c:\spama\spamassassin.exe -e c:\DATA\~BLAH~9.MAI > c:\DATA\~BLAH~9.MAIL"" ", 1, TRUE)

Open in new window

...and...
Set WshShell = WScript.CreateObject("WScript.Shell")
	intReturn = WshShell.Run("cmd.exe c:\spama\spamassassin.exe -e c:\DATA\~BLAH~9.MAI > c:\DATA\~BLAH~9.MAIL ", 1, TRUE)

Open in new window

...Both just open a CMD and sit there. Did I mis-understand you?

GH
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
can you tell if the spamassassin program is running or ran?
0
 
LVL 11

Author Comment

by:G_H
Comment Utility
Sorry for the delay, this has been difficult for me to test.

It does not look like spamassassin ran at all, and the cmd.exe created in task manager never disappears.

Where should I look next?

GH
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 250 total points
Comment Utility
The /K parameter will cause the command window to close after execution.

If you open a command prompt window and run your command:
c:\spama\spamassassin.exe -e c:\DATA\~BLAH~9.MAI > c:\DATA\~BLAH~9.MAIL
what happens?
0
 
LVL 11

Author Comment

by:G_H
Comment Utility
@aikimark

I ran a VBS with the CMD.exe /K and the window stayed open. (Although SA ran).

I tried SA directly from the command line, and it works.

I tried a VBS file with CMD.exe /C and SA ran, and the window closed.

Hoorah!

When I get a lttle more time, I will assemble the full code in VBS and test properly...

GH
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 250 total points
Comment Utility
oops.  You're right.  It is the /C, not the /K that terminates the window.  Good catch.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Author Comment

by:G_H
Comment Utility
OK, I have boiled it down to this:

In VBS I did this:
SpamAssassinCommand = "cmd.exe /C ""c:\spama\spamassassin.exe -e " & FileName & " > " & FileName & "L"""
SaveToLog SpamAssassinCommand
Set WshShell = WScript.CreateObject("WScript.Shell")
intReturn = WshShell.Run(SpamAssassinCommand, 1, TRUE)

Open in new window


The result is a file with "L" on the end, which only contains:
Return-Path: <email@deleted.domain>
(Yes it does have the real and proper FROM address, I just removed it so I don't get SPAM) LOL

As you can see the command is saved, so I recreate everything, and then run what was saved in the Log at the command prompt:
cmd.exe /C "c:\spama\spamassassin.exe -e c:\DATA\XXX.MAI > c:\DATA\XXX.MAIL"

Open in new window


This has the correct effect of putting a scanned copy of the file in the "L" file.

Why am I getting a different result? Do I need to escape some chars?

GH
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
I don't know.  I don't have Spamassassin.
0
 
LVL 11

Accepted Solution

by:
G_H earned 0 total points
Comment Utility
OK, I have finally got some reliable results...

If I run SpammAssassin from VBS, whatever I do VBS will never wait for SpamAssassin to finish. So SpamAssassin has to be done in CMD.

Further the event called by MailEnable will not wait for a VBS to finish, so what MailEnable must call a CMD.

So the incredibly convoluted process goes something like this:

Mailenable calls FilterA.CMD

FilterA.CMD runs FilterB.VBS (with /WAIT)

FilterB.VBS does some other stuff, then calls FilterC.CMD (with /C)

FilterC.CMD then calls SpamAssassin (with /WAIT).

All then runs and waits for each other part to finish.

As I said above, this is so ridiculous, I cannot believe there is not a better way...

GH
0
 
LVL 11

Author Comment

by:G_H
Comment Utility
With the above solution, from myself, I would like to award some points.

Maybe a 50-50 split between Myself and aikimark. Any Objections?

GH
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
you can not receive points from your own question.

have you tried launching a batch file from within your VBS and waiting for it to finish?
0
 
LVL 11

Author Comment

by:G_H
Comment Utility
Yes:

FilterB.VBS does some other stuff, then calls FilterC.CMD (with /C)
...But This seems to be two unnecessary steps, As:

1. I can only get ME to launch a batch and wait, it will launch a VBS, but will not wait, so I have to do a Launch a CMD to launch the VBS.

2. The VBS will not wait for SA to finish, so I get it to run a CMD, which will run (and wait for SA).

I see under my Answer above the option to "Accept Multiple Solutions"...

GH
0
 
LVL 45

Expert Comment

by:aikimark
Comment Utility
yes.  you can accept multiple comments as the solution, including your own comment.  However, your solution comment will not convey any points to you.
0
 
LVL 11

Author Closing Comment

by:G_H
Comment Utility
aikimark provided an pointer to switches to use when calling programs from Batch Files.

I did a lot of testing to find out the difference between running programs from VBS vs CMD vs BAT to come to the final conclusion..

GH
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Resolve DNS query failed errors for Exchange
Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
In this video we show how to create a Distribution Group in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >>…
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now