Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-01-14
16
Medium Priority
?
1,010 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 53

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 46

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 46

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 46

Assisted Solution

by:aikimark
aikimark earned 750 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 46

Assisted Solution

by:aikimark
aikimark earned 750 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 46

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 46

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 46

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The new Gmail Phishing Scam going around is surprising even the savviest of users with its sophisticated techniques.
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
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 >>…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

670 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