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

# 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_sDQ          = """"

Sub OnDeliverMessage(oMessage)

bPipeMessage = True
Else
bPipeMessage = False

Set obRecipients = oMessage.Recipients

For i = 0 to obRecipients.Count - 1
Set obRecipient = obRecipients.Item(i)

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

0
bruhast
1 Solution

Commented:
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

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.