• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

Pipe e-mail to php script with vbs script

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
bruhast
Asked:
bruhast
1 Solution
 
David LeeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now