Pipe e-mail to php script with vbs script

Posted on 2009-04-26
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 = "", all emails to 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*********** 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


      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


   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

Question by:bruhast
    1 Comment
    LVL 76

    Accepted Solution

    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


    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now