The below script lets you pipe all emails to the PHP executable. The script will be executed after hMailServer has accepted the message, but before it has been delivered to the recipients accounts.
Usage
1) Copy the above code to your EventHandlers.vbs
2) Edit the settings in the top to suite your needs.
2) In hMailAdmin, go to the Scripts section an reload the script.
g_sPHPPath - Path to the PHP executable
g_sScriptPath - Path to the PHP script that PHP should run
g_sPipeAddress - Email address that receives the messages that should be piped. If you leave it empty, all email messages will be piped.
Code: Select all
Const g_sPHPPath = "C:\path\to\php.exe"
Const g_sScriptPath = "C:\path\to\script.php"
Const g_sPipeAddress = "something@yourdomain.com"
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
This PHP script reads the email from stdin and writes it together with a timestamp in C:\temp\output.txt. This is only a sample script that should not be used in production. (If two messages are delivered at the same time, output.txt file might get corrupt.)
Code: Select all
<?
$email = file_get_contents('php://stdin');
$handle = fopen("C:\\temp\\output.txt", "a");
fwrite($handle, date("Y-m-d H:i:s"));
fwrite($handle, "\r\n");
fwrite($handle, $email);
fwrite($handle, "\r\n");
fclose($handle);
?>