• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1027
  • Last Modified:

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

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
G_H
Asked:
G_H
  • 8
  • 7
3 Solutions
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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
 
aikimarkCommented:
instead of running the spam assassin command directly, run CMD.exe followed with the spam assassin command
0
 
G_HAuthor Commented:
@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
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

 
aikimarkCommented:
can you tell if the spamassassin program is running or ran?
0
 
G_HAuthor Commented:
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
 
aikimarkCommented:
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
 
G_HAuthor Commented:
@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
 
aikimarkCommented:
oops.  You're right.  It is the /C, not the /K that terminates the window.  Good catch.
0
 
G_HAuthor Commented:
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
 
aikimarkCommented:
I don't know.  I don't have Spamassassin.
0
 
G_HAuthor Commented:
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
 
G_HAuthor Commented:
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
 
aikimarkCommented:
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
 
G_HAuthor Commented:
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
 
aikimarkCommented:
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
 
G_HAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

NEW Internet Security Report Now Available!

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out this quarters report on the threats that shook the industry in Q4 2017.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now