Link to home
Start Free TrialLog in
Avatar of shawn857
shawn857

asked on

Windows email client that will run program with parameters based on email subject/body/From, etc ?

Hi experts, I need a Windows email client that will run a Windows command-line EXE and be able to send parameters to it based on what is in the subject/body/From of the email message. And also, after my EXE has run, a small text file gets created that needs to be immediately emailed back (as an attachment) to the sender of the email. Now that i think of it more, I suppose the email client could also launch a .BAT somehow to do all this, instead of an EXE... but can parameters be passed to a .BAT?
   Anyhoo, would anyone know of a powerful enough Windows email software that can automate this process? Or maybe some kind of "macro" tool that could handle it?

Thanks!
   Shawn
Avatar of shawn857
shawn857

ASKER

Hi, would anyone be able to help please?

Thanks
   Shawn
Avatar of David Johnson, CD
you need to receive an email and then run a program if it has specified word in its subject  easily doable with outlook rules
you can use a simple powershell script to send your item
$body = get-content results.txt
send-mailmessage -from "user@example.com" -to "touser@" -subject 'Test Email' -body $body -credential user@example.com -smtpserver smtp.example.com

Open in new window

Thanks David... I've never used Outlook nor Powershell before so I may need a bit of hand-holding through this. Firstly, will Outlook Express work for me, or do I need the full-blown paid-version of Outlook?
   To be more specific about my needs - everything I need to grab will be in the Subject line of the incoming email. No need to look for specific words - I'll be taking the full contents of the Subject field (it's going to be just one long character string) and passing this, along with a few other static parameters, to my EXE. So I gather Outlook handles this part, and then once my EXE has finished running, I have another Outlook rule to run the Powershell command to email back the result file? is that how it works? So Outlook can invoke Powershell with the necessary parameters such as the recipient email address, etc?

Thanks!
    Shawn
Basically you'll need a email client capable of running filters and capable of running external programs as filter actions. I'm not sure if Outlook can do that without using some VBA macro, but with weaving some VBA magic you could achieve that. Another email client I know of with such features is PMMail2000 (although that thing is godd, but quite old and no longer maintained).

From that base you could call a batch or powershell script which could do anything you want it to.

Sending the results from a batch is easy with BLAT.

The most flexible and independent way:
If your'e willing to knit something in .NET, you could easily browse messages, download a message, inspect it, run external programs depending on the content and even send out results (most of the email capabilities are already part of the .NET framework ...).
full outlook, outlook express is dead and gone with xp.
Thanks Frank - PMMail 2000 sounds good to me, I don't care if it's not supported anymore, as long as it works for me without having to re-invent the wheel (I need to find a solution rather quickly). Would I need a VBA macro with PMMail?
   Also, I know nothing about .NET - I'd rather not go down that route.

Thanks David -ok, no Outlook Express. Could you address the remaining questions please from my last post?

Thanks!
    Shawn
If this then that (ifttt) can do all sorts of fun things just like this. Here is an example using sms and Dropbox but it has email and tons of other connectors
http://www.makeuseof.com/tag/how-to-issue-a-command-to-your-computer-with-a-text-message/
OK guys, I found and installed a trial version of Outlook 2010 and I already have Powershell on my Vista machine (didn't know I already had it).  I snooped around Outlook a bit and saw how rules are created. I'm looking at the place now where you can select to "start an application" or "run a script" (among other choices)... I hope someone can give me some guidance on what I need to do. Let me outline exactly what I need:

(1) I've set up the mailbox on Outlook as, let's say: abc@xyz.com
(2) Whenever someone sends an email to abc@xyz.com, I want Outlook to take all the text that is in the SUBJECT field (it will be a string of characters), and send that as a parameter to an application of mine (an EXE file, let's call it MYAPP.EXE).
(3) MYAPP.EXE will take the parameters and generate a special code and write it to a file 'result.txt'
(4) I then need to send an email back to the original sender, with a canned message in the body of the email, and this result.txt file as an attachment.

Could someone outline how I'd set this up in Outlook/Powershell please? I know absolutely nothing about Powershell... it would be great if you could provide some code.

Thanks!
    Shawn
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so I will have to make a VBA script? I don't really know VBA...
is it possible to call a .BAT batch file from Outlook, and also pass parameters to it?

Thanks
   Shawn
you have to use vba scripting to get the subject to pass as the argument
OK David... could you give me a small sample of VBA on how it would be done to pass the SUBJECT line as a parameter? Also, where do I create the VBA script - in Outlook, or in Excel?

Thanks
   Shawn
Regarding PMMail2000:

With PMMail there are no VBA macros - to be true, there's definitely NO macro facility within, which is a pro in these times ... besides of that the display engine for HTML mails is well outdated and presents nasty results.

The main jewel inside is the very, very good filter engine. PMMail2000 supports POP3. I for myself use it with stunnel to get encrypted mail exchange.

PMMail2000 is shareware, so you could try before buy.

When a mail triggers the filter, PMMail would spawn to a batch file which could do anything you want to. For sending out emails from batch files I recommend again BLAT (d/l here).
Well, I think I'm getting there guys - I've cobbled something together. I made a .BAT file that runs my EXE that i can successfully invoke from VBA in Outlook and successfully pass the SUBJECT line of the incoming email as a parameter to the BAT file. I got that part all down - the BAT file successfully creates my result.txt file and now I need to expand my VBA macro to grab this file and email it back to the original email sender (Frank - I had trouble getting BLAT to work for me). Googling around I found some VBA code and here's what my VBA macro looks like now:

Public Sub dsdemovba(Mail As Outlook.MailItem)
  Dim OL              As Object
  Dim EmailItem       As Object
  Dim Doc             As Document
  Dim SubjectLine As String
  Dim SendBackTo As String
  
  UserCode = Mail.Subject
  SendBackTo = Mail.Sender

  Call Shell("c:\codelock\MakeDemocodeFile.bat " & UserCode, vbMaximizedFocus)
  
  Set OL = CreateObject("Outlook.Application")
  Set EmailItem = OL.CreateItem(olMailItem)
  Set Doc = "c:\codelock\result.txt"
  Doc.Save
  With EmailItem
     .Subject = "Your attached file"
     .Body = "Here's the body of the email"
     .To = SendBackTo
     .Attachments.Add Doc.FullName
     .Send
  End With
  
  Set Doc = Nothing
  Set OL = Nothing
  Set EmailItem = Nothing
End Sub

Open in new window


... but there's a compile error when I try to run this VBA. It doesn't like the line "Dim Doc As Document" and says "Compile Error: User-defined type not defined". I took that code right from this site:

http://www.vbaexpress.com/kb/getarticle.php?kb_id=98

Could anyone offer any advice on what the problem could be?

Thanks!
    Shawn
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Making more progress guys - almost finished actually! Figured out how to do the file attachment to my outgoing email in VBA:

With EmailItem
    ...
    .Body = "here is the text of the email body"
    .Attachments.Add "c:\myfolder\myfile.txt"
    ...
End With

The *only* thing left I'd like to be able to do is to be able to import a text file into the email ".Body", instead of assigning a static text string to it. I tried a few things I found on the net but for some odd reason, they caused the prior call of my BAT file to stop working altogether... weird. Anyone have any thoughts on this one last issue?

Thanks!
   Shawn
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Aaron... yes this was one of the suggestions I tried, and it caused my BAT file call to not work for some reason!

Thanks
   Shawn
Aaron, I take that back... I must have done something wrong before cause your last suggestion has now worked for me. I now have everything done and working *SLICK!* Thank you all!

Cheers
   Shawn