Solved

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

Posted on 2013-01-14
16
962 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
ID: 38776794
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
ID: 38778730
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
ID: 38778916
@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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 45

Expert Comment

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

Author Comment

by:G_H
ID: 38798270
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
ID: 38799033
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
ID: 38799426
@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
ID: 38799733
oops.  You're right.  It is the /C, not the /K that terminates the window.  Good catch.
0
 
LVL 11

Author Comment

by:G_H
ID: 38802798
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
ID: 38802966
I don't know.  I don't have Spamassassin.
0
 
LVL 11

Accepted Solution

by:
G_H earned 0 total points
ID: 38822021
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
ID: 38822032
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
ID: 38822250
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
ID: 38822293
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
ID: 38822680
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
ID: 38843069
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

New-MailboxSearch Powershell Command and step by step approach to Search and Extract Emails form Exchange 2013 Journaling server.
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

803 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