Solved

# Pipe e-mail to php script with vbs script

Posted on 2009-04-26
426 Views
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
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

0

## Featured Post

### Suggested Solutions

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…