Php “什么是对象?”;“oMessage”;在hMailServer电子邮件管道中?

Php “什么是对象?”;“oMessage”;在hMailServer电子邮件管道中?,php,vba,outlook,Php,Vba,Outlook,我正在将找到的一些hMailServer代码改编为MS Outlook vba。源代码位于 我已经在hMailServer和Thunderbird中测试了这段代码,并使其正常工作。但是,在部署中,我希望我不能访问hMailServer,邮件客户端可能是MS Outlook 在源代码中,作者引用了“oMessage”,但是,嗯,我不能确定“oMessage”应该是什么对象,在我的改编中,在命令行字符串中导致了一个错误,错误当然是“object required”。到那时为止,我的vba脚本工作正常

我正在将找到的一些hMailServer代码改编为MS Outlook vba。源代码位于

我已经在hMailServer和Thunderbird中测试了这段代码,并使其正常工作。但是,在部署中,我希望我不能访问hMailServer,邮件客户端可能是MS Outlook

在源代码中,作者引用了“oMessage”,但是,嗯,我不能确定“oMessage”应该是什么对象,在我的改编中,在命令行字符串中导致了一个错误,错误当然是“object required”。到那时为止,我的vba脚本工作正常。因为hMailServer上的线程已经有好几年了,所以我不希望在那里发布的问题上得到回复

以下是原始源代码:

Const g_sPHPPath     = "C:\path\to\php.exe" 
Const g_sScriptPath  = "C:\path\to\script.php" 
Const g_sPipeAddress = "something@yourdomain.com"

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
以下是我的改编:

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

Sub OnDeliverMessage(oMessage)
Dim Explorer As Outlook.Explorer
Dim CurrentItem As Object

Set Explorer = Application.ActiveExplorer
If Explorer.Selection.Count Then
    Set CurrentItem = Explorer.Selection(1)
End If

If CurrentItem.Class = olMail Then
    Dim sender
    sender = CurrentItem.SenderEmailAddress
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

那么,有人能告诉我在Outlook模型中,oMessage对象等同于什么吗?在cmd字符串中,我应该在“oMessage.FileName”中查找什么?

收到hMailServer的回复:“它是hMailServer在接收消息(物理.EML文件)时创建的文件名,然后在客户端请求时流式传输到客户端。”

因此,参数“oMessage”是从hMailServer传递的,但在这个VBA自适应中不需要它

解决方案只是将电子邮件保存到过程主体“CurrentItem.SaveAs g_FileName,olTXT”中的文本文件中,其中g_FileName声明为常量

这样,电子邮件就被传送到一个文本文件,在那里可以用你选择的语言进行解析。在我的例子中,PHP检索“name”、“storenumber”、“phone number”等值并将其保存到MySQL数据库中

最后,Outlook中应用的规则是,当收到电子邮件时,将其移动到一个文件夹中,并调用OnDeliverMessage()脚本

修订后的守则是:

Const g_sPHPPath = "C:\xampp\php\php.exe"
Const g_sScriptPath = "C:\xampp\htdocs\Recycler\handler.php"
Const g_sPipeAddress = "someone@mail.net"
Const g_FileName = "C:\tmp\output.txt"
Const g_sDQ = """"

Sub OnDeliverMessage()
Dim Explorer As Outlook.Explorer
Dim CurrentItem As Object

Set Explorer = Application.ActiveExplorer
If Explorer.Selection.Count Then
    Set CurrentItem = Explorer.Selection(1)
End If

CurrentItem.SaveAs g_FileName, olTXT

If CurrentItem.Class = olMail Then
    Dim sender
    sender = CurrentItem.SenderEmailAddress
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 & g_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