?
Solved

Pipe e-mail to php script with vbs script

Posted on 2009-04-26
1
Medium Priority
?
437 Views
Last Modified: 2012-06-21
I'm using the included code to pipe an e-mail to a php script on arrival. I don't know VB very well, so I was hoping someone could help me.

The line that says: Const g_sPipeAddress = "" tells the mail server what incoming e-mails to run the script included on the line above. For instance, if that line said Const g_sPipeAddress = "nathanael@domain.com", all emails to nathanael@domain.com would have the script run. If the line had no address specified, it runs for all incoming mail. What I need to do is have all emails sent to post***********@domain.com have the script run. Would anyone be able to modify this script to help me?

Do I need to use a regular expression? If so, can you point me in the right direction on writing one?

Thank you!

Const g_sPHPPath     = "C:\path\to\php.exe"
Const g_sScriptPath  = "C:\path\to\script.php"
Const g_sPipeAddress = ""
 
const g_sDQ          = """"
 
Sub OnDeliverMessage(oMessage)
   
   If g_sPipeAddress = "" Then
      bPipeMessage = True
   Else
      bPipeMessage = False
 
      Set obRecipients = oMessage.Recipients
     
      For i = 0 to obRecipients.Count - 1
         Set obRecipient = obRecipients.Item(i)
         
         If LCase(obRecipient.Address) = LCase(g_sPipeAddress) Then
            bPipeMessage = True
         End If
      Next
   End If
     
   If bPipeMessage Then
      sCommandLine = "cmd /c type " & g_sDQ & oMessage.Filename & g_sDQ & " | " & g_sDQ & g_sPHPPath & g_sDQ & " " & g_sDQ & g_sScriptPath & g_sDQ
      Set oShell = CreateObject("WScript.Shell")
      Call oShell.Run(sCommandLine, 0, TRUE)
   End If
End Sub

Open in new window

0
Comment
Question by:bruhast
1 Comment
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 24281473
Hi, bruhast.

I'm not sure I understand your question.  Are you asking how you can compare the domain portion of the incoming email address to g_sPipeAddress?  If so, then you can use the InStr function.  Something like the code in the snippet.  InStr test to see if the second string occurs anywhere in the first string.  If it does, then it returns True.
         If InStr(1,LCase(obRecipient.Address), LCase(g_sPipeAddress)) Then
            bPipeMessage = True
         End If

Open in new window

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

864 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