Piping message to application

This section contains scripts that hMailServer has contributed with. hMailServer 4 is needed to use these.
Post Reply
User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Piping message to application

Post by martin » 2005-11-06 21:30

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

Example PHP-script
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);
?>
Last edited by martin on 2005-11-06 22:12, edited 4 times in total.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2005-11-06 21:49

Is there a way to limit this to a specific account such as support@domain.com?

User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2005-11-06 22:13

I've updated the script. Only messages to something@yourdomain.com will be piped. If you leave the address empty, all addresses will be piped.

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Post by ^DooM^ » 2005-11-07 13:08

Hey Martin.

Thankyou for this. It's exactly what I needed.

gabrielharrison
Normal user
Normal user
Posts: 61
Joined: 2004-12-13 15:40

Post by gabrielharrison » 2006-01-02 19:18

Has anyone got a variant of the script that can cope with multiple addresses and scripts? I want to implement the php-eml script on sourceforge and it has three scripts: post, subscribe and unsubscribe.

Happy New Year Everyone,

Gabriel

rebelo
New user
New user
Posts: 26
Joined: 2006-01-16 20:57

Post by rebelo » 2006-03-28 00:39

Hi.
Got here a similar situation but in a cgi script.
Have tried to work it out changing the paths to perl + script but does not work.

Any hints ?

User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-03-28 20:26

Would be helpful if you tell us what you mean with 'does not work'. Our suggestions may vary a bit depending on the actual result. Have you checked the hMailServer error log?

rebelo
New user
New user
Posts: 26
Joined: 2006-01-16 20:57

Post by rebelo » 2006-03-28 22:44

Ok, this is the only line diferent I find from when the script of this thread was activated:

"DEBUG" 472 "2006-03-27 23:45:37.735" "ClamWinVirusScanner::Scan() - C:\Programs\ClamWin\bin\clamscan.exe --database='C:\Documents and Settings\All Users\.clamwin\db' '{4EDCCC2C-D93B-4E56-9D75-B65F3246F8A6}.eml' --tempdir='C:\WINDOWS\Temp' - Returned 0"

joksi
Normal user
Normal user
Posts: 76
Joined: 2006-10-15 12:29

Post by joksi » 2006-10-15 12:31

I have a problem!

How can this VB-script be modified so it DELETES the original mail that was piped, as it works now the script leaves a copy of the mail in the mail inbox.

Thanks in advance

User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-10-15 12:54

After
Call oShell.Run(sCommandLine, 0, TRUE)
Add
Result.Value = 1

Then hMailServer will not deliver the message.

joksi
Normal user
Normal user
Posts: 76
Joined: 2006-10-15 12:29

Post by joksi » 2006-10-15 13:02

Thanks, great!

joksi
Normal user
Normal user
Posts: 76
Joined: 2006-10-15 12:29

Post by joksi » 2006-10-17 14:15

One more modification wanted!

If i want to enter more e-mail adresses that should be piped to different scripts? How can I achieve this?

Should i just enter this script again but with other details, or must the existing script be modified?

User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-10-17 14:21

The existing script must be modified (by someonw who knows VBA)

joksi
Normal user
Normal user
Posts: 76
Joined: 2006-10-15 12:29

Post by joksi » 2006-10-17 15:02

So it's not possible having more than one script to be run simultanous on message delivery?

Hmm, well, if not a solution would maybe be to use the same script for different purposes depending on the mail adress it was sent to. (by parsin the mail of course)

It should be possible to make 2 or 3 aliases for the one mail adress that gets piped?

joksi
Normal user
Normal user
Posts: 76
Joined: 2006-10-15 12:29

Post by joksi » 2006-10-17 15:06

Yes, i tried it right away, it worked with aliasing the piping adress and then in the PHP script check what the To: adress where, to achieve different things :)

User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2006-10-17 15:12

Yes, that's another way to solve it. :)

racman
Normal user
Normal user
Posts: 107
Joined: 2006-02-06 16:14

Post by racman » 2007-05-12 20:39

martin wrote:Yes, that's another way to solve it. :)
Hi Joksi,

How did you get the PHP script to check the "To:address"? Can you please provide me with your sample?

Thanks..

Racman

fingers
New user
New user
Posts: 7
Joined: 2005-08-22 14:33

Post by fingers » 2007-06-02 18:44

Hi;
I've utilised the script above (converted to only VBS no cgi) to save a message when it arrives but I cant get it to trigger when it is sent to ONLY an alias. It works correctly ( too well all messages to the account are run against the code) only to the account address

Code: Select all

Sub OnDeliverMessage(oMessage)
   ' 1) Copy this code to your EventHandlers.vbs OnDeliverMessage(oMessage)
   ' 2) Edit the settings here to suit your needs.
   Const g_sPipeAddress    = "account@domain.tdl"
   Const g_sFilePath       = "C:\test\message\"
   Const g_sFileName       = "output.txt"
   Const OverwriteExisting = True
   ' 2) In hMailAdmin, go to the Scripts section an reload the script.
   If g_sPipeAddress = "" Then
      bPipeMessage = True
   Else
      bPipeMessage = False
      ' Check The Message recipient(s)
      Set obRecipients = oMessage.Recipients
      For i = 0 to obRecipients.Count - 1
         Set obRecipient = obRecipients.Item(i)
         If StrComp(g_sPipeAddress, obRecipient.Address, 1) = 0 Then
            bPipeMessage = True
         End If
      Next
   End If
   If bPipeMessage Then
      'create a variable
      Dim g_sobjFSO
      Set g_sobjFSO = CreateObject("Scripting.FileSystemobject")
      g_sobjFSO.CopyFile oMessage.Filename, g_sFilePath & g_sFileName, OverwriteExisting
      Set g_sobjFSO = Nothing
      ' To Delete the Message after saving as a file use Result.Value = 1
      ' Result.Value = 1
   End If
End Sub
is there a way to get the messages actual TO: address
from the oMessage or does it only provide the mail accounts "primary" address and so i will have to add a subject string checking IF THEN ENDIF

diginin
New user
New user
Posts: 2
Joined: 2008-03-26 10:10

Re:

Post by diginin » 2008-03-26 11:51

rebelo wrote:Hi.
Got here a similar situation but in a cgi script.
Have tried to work it out changing the paths to perl + script but does not work.

Any hints ?
Does any one know if this is working with perl or not?

I am looking for c:\> perl.exe Scriptname.pl < <output from script>

Does that even make sense? Thanks for all responses.

diginin
New user
New user
Posts: 2
Joined: 2008-03-26 10:10

Re: Re:

Post by diginin » 2008-12-05 14:09

diginin wrote:
rebelo wrote:Hi.
Got here a similar situation but in a cgi script.
Have tried to work it out changing the paths to perl + script but does not work.

Any hints ?
Does any one know if this is working with perl or not?

I am looking for c:\> perl.exe Scriptname.pl < <output from script>

Does that even make sense? Thanks for all responses.
This works fine with perl. I have tested it extensively.

User avatar
kani
New user
New user
Posts: 18
Joined: 2010-04-01 18:31

Re: Piping message to application

Post by kani » 2010-07-23 13:14

I tried this script it seems my php script is not being executed, I debugged the command it tries to execute, here is the command for the shell, not sure what I am missing here.

Thanks for your help.

'cmd /c type C:\Program Files\hMailServer-2008\Data\{60DE1CCD-A375-494F-AF1F-F4A92C701A02}.eml | C:/PHP-5/php.exe C:/Inetpub/wwwroot/api/hmail-parser.php'

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Piping message to application

Post by ^DooM^ » 2010-07-23 13:16

could be due to the space between program and files

enclose the path "quotes"
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

Crypty
New user
New user
Posts: 4
Joined: 2010-07-09 14:18

hmailserver and piping for Kayako

Post by Crypty » 2010-07-29 20:21

Hi,

Kayako SupportSuite, hmailServer piping

Regards.

Code: Select all

<%
Const batPath  = "C:\kayakoHmailPiping.bat" 
Const PipeAddress = "your@email.com"

Sub OnDeliverMessage(oMessage) 
   
   If PipeAddress = "" 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(PipeAddress) Then
            bPipeMessage = True
         End If
      Next
   End If
      
   If bPipeMessage Then
      Set oShell = CreateObject("WScript.Shell") 
      Call oShell.Run batPath
      Set oShell = nothing
   End If
End Sub 
%>

>>>> kayakoHmailPiping.bat file content<<<<<

start iexplore "http://www.yourdomain.com/cron/index.php?_t=parser"

FiShBuRn
Normal user
Normal user
Posts: 88
Joined: 2007-06-29 16:43

Re: Piping message to application

Post by FiShBuRn » 2011-06-01 16:55

thanks for the script, working great :)

thedealer
New user
New user
Posts: 7
Joined: 2011-07-14 18:39

Re: Piping message to application

Post by thedealer » 2011-07-15 17:51

FiShBuRn wrote:thanks for the script, working great :)
Same here, really pleased with the fixes and stability that have taken place over the years since it was released. This is super helpful for my job (I think my boss might actually think I am getting things done)

osvaldoPT
New user
New user
Posts: 6
Joined: 2011-08-25 20:16

Re: Piping message to application

Post by osvaldoPT » 2011-10-12 21:04

i cant get it to work, runing 5.4 and using a catch all email address could there be any problem with it?

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Piping message to application

Post by ^DooM^ » 2011-10-13 00:18

Should still work.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

cncJasonB
New user
New user
Posts: 7
Joined: 2011-12-05 21:41

Re: Piping message to application

Post by cncJasonB » 2011-12-08 17:31

This was extremely useful to me, thanks!

jazcam
New user
New user
Posts: 3
Joined: 2015-12-02 15:58
Contact:

Re: Piping message to application

Post by jazcam » 2015-12-02 16:10

I'm writing some updates to your code -- less interested in the recipient than the sender, and I'm writing into a workable vba script to run in MS Outlook. I'm having a problem with oMessage, particularly in the sCommandLine where it references oMessage.FileName. I'm not following where oMessage actually is assigned or inherits a FileName, or what object in the Outlook model it represents.

The error is at oMessage.FileName where oMessage has not been defined as an object.

my vba code looks like this:

Code: Select all

Const g_sPHPPath = "C:\xampp\php\php.exe"
Const g_sScriptPath = "C:\xampp\htdocs\Recycler\test.php"
Const g_sPipeAddress = "somebody@mail.net"

Const g_sDQ = """"

Code: Select all

Sub OnDeliverMessage(oMessage)
    Dim Explorer As Outlook.Explorer
    Dim CurrentItem As Object
 
    Set Explorer = Application.ActiveExplorer
    If Explorer.Selection.Count Then
        ' Get the first selected item.
        Set CurrentItem = Explorer.Selection(1)
    End If
    
    ' Check for the type of the selected item as only the
    ' MailItem object has the Sender property.
    If CurrentItem.Class = olMail Then
        Dim sender
        Dim msg
        sender = CurrentItem.SenderEmailAddress
        msg = CurrentItem.Body
    End If
    
    If g_sPipeAddress = "" Then
        bPipeMessage = True
    Else
        If LCase(sender) = 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

User avatar
jimimaseye
Moderator
Moderator
Posts: 10060
Joined: 2011-09-08 17:48

Re: Piping message to application

Post by jimimaseye » 2015-12-02 19:04

(If I have understood you correctly......)

This script doesnt run in outlook, it is written PURELY for EVENTHANDLERS.VBS script in HMAILSERVER. The oMessage.filename is an object supplied by Hmailserver. Outlook wont have a clue what it is talking about.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

jazcam
New user
New user
Posts: 3
Joined: 2015-12-02 15:58
Contact:

Re: Piping message to application

Post by jazcam » 2015-12-02 20:55

I understand that it is written for hMailServer. Howerver, if I can get a clue as to what oMessage.FileName is, I can adapt it.

User avatar
jimimaseye
Moderator
Moderator
Posts: 10060
Joined: 2011-09-08 17:48

Re: Piping message to application

Post by jimimaseye » 2015-12-02 22:34

it is the filename that hmailserver creates when receiving a message (the physical .EML file) which is then streamed to clients when clients request it.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

jazcam
New user
New user
Posts: 3
Joined: 2015-12-02 15:58
Contact:

Re: Piping message to application

Post by jazcam » 2015-12-03 00:04

Ok, thanks.

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2015-12-03 01:40

Please ALSO note that the COM API changed significantly between ver 4 and ver 5 of hMailsevrer, hence the separate forum sections.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-25 23:47

mattg wrote:Please ALSO note that the COM API changed significantly between ver 4 and ver 5 of hMailsevrer, hence the separate forum sections.
Is there any version 5 scripts? I searched the ver5 forum and cannot locate any new information on this.

Basically I am looking for piping from hmail to a php script made by InvisionPowerBoard for piping into a support ticket.

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2016-05-26 00:18

Have you tried this script in newer versions?

I've not seen any discussion on piping for many many years. This is the only thread I can recall about it.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-26 02:40

ive tried the one that's out there, but doesn't seem to dispatch the message out to the receiving php script.

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2016-05-26 02:54

Can you please post the script as you have tried it, and any error messages that you get
Also, does your hMailserver work fine otherwise?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-26 03:27

mattg wrote:Can you please post the script as you have tried it, and any error messages that you get
Also, does your hMailserver work fine otherwise?
yea all other functions work fine, just the scripting i found searching around here. my hmail is running 5.6.4-B2283

Code: Select all

Const g_sPHPPath     = "<path>\php.exe"
Const g_sScriptPath  = "<path>\www\forums\applications\core\interface\incomingemail\piping.php"
Const g_sPipeAddress1 = "billing@gcinema.net"
Const g_sPipeAddress2 = "abuse@gcinema.net"
const g_sDQ          = """"
Sub OnDeliverMessage(oMessage)
    If g_sPipeAddress1 = "" Or g_sPipeAddress2 = "" 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_sPipeAddress1) Then
            bPipeMessage = True
         End If

         If LCase(obRecipient.Address) = LCase(g_sPipeAddress2) 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

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2016-05-26 05:01

No error log created in the hmailserver log directory?
I'm guessing that this is part of your eventhandler.vbs, and that scripts are enabled and loaded.

If you aren't already using the eventhandlers.vbs, can you please add this to it and reload the script.

(This little sub should just write the message subjects to the events_hMailserver.log) you can remove it once you confirm that scripts work by an event log being created.

Code: Select all

Sub OnDeliveryStart(oMessage)
	eventlog.write(now() & "  " &  oMessage.subject)
End Sub
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-26 05:32

mattg wrote:No error log created in the hmailserver log directory?
I'm guessing that this is part of your eventhandler.vbs, and that scripts are enabled and loaded.

If you aren't already using the eventhandlers.vbs, can you please add this to it and reload the script.

(This little sub should just write the message subjects to the events_hMailserver.log) you can remove it once you confirm that scripts work by an event log being created.

Code: Select all

Sub OnDeliveryStart(oMessage)
	eventlog.write(now() & "  " &  oMessage.subject)
End Sub
yep adding that now prints into a hmailserver_events.log with subject name as intented ; but no error logs

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2016-05-26 07:29

Ok so let's try this

Code: Select all

Const g_sPHPPath     = "<path>\php.exe"
Const g_sScriptPath  = "<path>\www\forums\applications\core\interface\incomingemail\piping.php"
Const g_sPipeAddress1 = "billing@gcinema.net"
Const g_sPipeAddress2 = "abuse@gcinema.net"
const g_sDQ          = """"
Sub OnDeliverMessage(oMessage)
    If g_sPipeAddress1 = "" Or g_sPipeAddress2 = "" 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_sPipeAddress1) Then
            bPipeMessage = True
         End If

         If LCase(obRecipient.Address) = LCase(g_sPipeAddress2) Then
            bPipeMessage = True
         End If

      Next
   End If
     
   If bPipeMessage Then
      eventlog.write(now() & "  " &  oMessage.subject & " Message pipelined")
      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")
      eventlog.write(now() & "  " &  oMessage.subject & " Shell Created")
      Call oShell.Run(sCommandLine, 0, TRUE)
   End If
End Sub
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-26 08:30

odd no change. no error or any new log types (such as message pipelined or shell created)

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2016-05-26 09:53

Then put log lines in a few places higher up the script


My guess is that the oBrecipient.address doesn't match the addresses that are entered
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-30 11:14

did a little searching on the forums and found a oMessage.To, when logged it logs the correct email address, so this is what I have now.

Code: Select all

Sub OnDeliverMessage(oMessage)
	If g_sPipeAddress1 = "" Or g_sPipeAddress2 = "" Then
      bPipeMessage = True
      Else
      bPipeMessage = False

		Set obRecipients = oMessage.To
	  'eventlog.write(now() & "  " &  oMessage.To & "  "  &  oMessage.subject)
     
      For i = 0 to obRecipients.Count - 1
         Set obRecipient = obRecipients.Item(i)
 
         If LCase(obRecipient.Address) = LCase(g_sPipeAddress1) Then
            bPipeMessage = True
         End If

         If LCase(obRecipient.Address) = LCase(g_sPipeAddress2) Then
            bPipeMessage = True
         End If

      Next
   End If
     
   If bPipeMessage Then
      eventlog.write(now() & "  " &  oMessage.subject & " Message pipelined")
      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")
      eventlog.write(now() & "  " &  oMessage.subject & " Shell Created")
      Call oShell.Run(sCommandLine, 0, TRUE)
   End If
End Sub
then when running this along with the consts in above posts, I get this in the error.
ERROR" 12788 "2016-05-30 04:09:05.498" "Script Error: Source: Microsoft VBScript runtime error - Error: 800A01A8 - Description: Object required: '[string: "billing@gcinema.net"]' - Line: 43 Column: 0 - Code: (null)"

User avatar
SorenR
Senior user
Senior user
Posts: 6315
Joined: 2006-08-21 15:38
Location: Denmark

Re: Piping message to application

Post by SorenR » 2016-05-30 12:14

FYI...

Recipient = envelope "RCPT TO"
oMessage.To = HeaderValue "TO"
SørenR.

Woke is Marxism advancing through Maoist cultural revolution.

User avatar
mattg
Moderator
Moderator
Posts: 22437
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Piping message to application

Post by mattg » 2016-05-30 12:19

Which is line 43?
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-30 22:17

mattg wrote:Which is line 43?
Set obRecipients = oMessage.To

User avatar
jimimaseye
Moderator
Moderator
Posts: 10060
Joined: 2011-09-08 17:48

Re: Piping message to application

Post by jimimaseye » 2016-05-30 23:38

Your last code modified:

Code: Select all

Sub OnDeliverMessage(oMessage)
   If g_sPipeAddress1 = "" Or g_sPipeAddress2 = "" Then
      bPipeMessage = True
      Else
      bPipeMessage = False

     'eventlog.write(now() & "  " &  oMessage.To & "  "  &  oMessage.subject)

      for i = 0 to oMessage.recipients.count -1
 
         If LCase(oMessage.Recipients(j).Address) = LCase(g_sPipeAddress1) Then
            bPipeMessage = True
         End If

         If LCase(oMessage.Recipients(j).Address) = LCase(g_sPipeAddress2) Then
            bPipeMessage = True
         End If

      Next
   End If
     
   If bPipeMessage Then
      eventlog.write(now() & "  " &  oMessage.subject & " Message pipelined")
      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")
      eventlog.write(now() & "  " &  oMessage.subject & " Shell Created")
      Call oShell.Run(sCommandLine, 0, TRUE)
   End If
End Sub
(I dont necessarily agree with the logic, just modified so it doesnt error for you)
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-31 01:45

jimimaseye wrote:(I dont necessarily agree with the logic, just modified so it doesnt error for you)
reasoning why I was going towards the oMessage.To was becasue it would grab the billing@gcinema.net ; when i was logging using the oMessage.Recipients(j).Address it would print my personal email address.

Billing @ gcinema.net is setup as an DistroList to send to madman32395 @ gcinema.net (only the one email since I dont have other people doing billing, unlike the admin @ gcinema.net address which has 4 recipients behind it.

madman32395
New user
New user
Posts: 9
Joined: 2016-05-25 23:45

Re: Piping message to application

Post by madman32395 » 2016-05-31 09:33

jimimaseye wrote:Your last code modified:

Code: Select all

Sub OnDeliverMessage(oMessage)
   If g_sPipeAddress1 = "" Or g_sPipeAddress2 = "" Then
      bPipeMessage = True
      Else
      bPipeMessage = False

     'eventlog.write(now() & "  " &  oMessage.To & "  "  &  oMessage.subject)

      for i = 0 to oMessage.recipients.count -1
 
         If LCase(oMessage.Recipients(j).Address) = LCase(g_sPipeAddress1) Then
            bPipeMessage = True
         End If

         If LCase(oMessage.Recipients(j).Address) = LCase(g_sPipeAddress2) Then
            bPipeMessage = True
         End If

      Next
   End If
     
   If bPipeMessage Then
      eventlog.write(now() & "  " &  oMessage.subject & " Message pipelined")
      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")
      eventlog.write(now() & "  " &  oMessage.subject & " Shell Created")
      Call oShell.Run(sCommandLine, 0, TRUE)
   End If
End Sub
(I dont necessarily agree with the logic, just modified so it doesnt error for you)
changed the code up to use oMessage.To and now it prints the piping log. :D

Code: Select all

Const g_sPHPPath     = "<path>\php.exe"
Const g_sScriptPath  = "<script path>"
Const g_sPipeAddress1 = "<email1>"
Const g_sPipeAddress2 = "<email2>"
const g_sDQ          = """"
Sub OnDeliverMessage(oMessage)
   If g_sPipeAddress1 = "" Or g_sPipeAddress2 = "" Then
      bPipeMessage = True
      Else
      bPipeMessage = False

     'eventlog.write(now() & "  " &  oMessage.To & "  "  &  oMessage.subject)

      for i = 0 to oMessage.recipients.count -1
 
         If LCase(oMessage.To) = LCase(g_sPipeAddress1) Then
            bPipeMessage = True
         End If

         If LCase(oMessage.To) = LCase(g_sPipeAddress2) Then
            bPipeMessage = True
         End If

      Next
   End If
     
   If bPipeMessage Then
      'eventlog.write(now() & "  " &  oMessage.subject & " Message pipelined")
      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")
      'eventlog.write(now() & "  " &  oMessage.subject & " Shell Created")
      Call oShell.Run(sCommandLine, 0, TRUE)
   End If
End Sub
12788 "2016-05-31 02:25:17.395" "5/31/2016 2:25:17 AM test pipe Message pipelined"
12788 "2016-05-31 02:25:17.424" "5/31/2016 2:25:17 AM test pipe Shell Created"


so i'm going to guess hmail is piping correctly, now its just to figure IP.Board's piping issue now on the receiving end. Thank you two very much.

in my case oMessage.To will work, but in others your origional code would work.

Post Reply