Private WithEvents myOlItems As Outlook.Items
Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace(“MAPI”)
Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub myOlItems_ItemAdd(ByVal item As Object)
On Error GoTo ErrorHandler
Dim Msg As Outlook.MailItem
If TypeName(item) = “MailItem” Then
Set Msg = item
If Msg.Subject Like “*關鍵字*” Then
Set objHTTP = CreateObject(“MSXML2.ServerXMLHTTP”)
URL = “http://127.0.0.1/index.phpsubject=” & Msg.Subject
objHTTP.Open “POST”, URL, False
objHTTP.setRequestHeader “User-Agent”, “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”
objHTTP.Send (“”)
End If
‘MsgBox Msg.Subject
‘MsgBox Msg.Body
End If
ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & ” -” & Err.Description
Resume ProgramExit
End Sub