我適應一些hMailServer代碼,我發現到MS Outlook VBA。源代碼是在https://www.hmailserver.com/forum/viewtopic.php?f=14&t=2960什麼對象是「oMessage」在hMailServer郵件管道?
我在hMailServer和雷鳥測試此代碼,並將它的工作。但是,在部署中,我希望我無法訪問hMailServer,並且郵件客戶端很可能是MS Outlook。
在源代碼中,作者引用了「oMessage」,但是,我不能確定「oMessage」應該是什麼對象,並且在我的改寫中會導致錯誤是錯誤的命令行字符串當然,「需要的對象」。到那時,我的vba腳本工作正常。由於hMailServer的線程已經有幾年了,所以我不希望在我發佈的問題上得到答覆。
原來這裏是源代碼:
Const g_sPHPPath = "C:\path\to\php.exe"
Const g_sScriptPath = "C:\path\to\script.php"
Const g_sPipeAddress = "[email protected]"
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 = "[email protected]"
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
那麼,誰能告訴我什麼對象oMessage將等同於在Outlook模式?在cmd字符串中,我應該在「oMessage.FileName」中查找什麼?