使用vbscript处理传入的电子邮件

Sid*_*out 5 vbscript outlook

问题:使用vbscript处理传入的电子邮件。

Outlook版本:Outlook 2000

描述:我不能为此使用VBA,因为我相信Outlook 2000不允许您从规则向导中运行VBA脚本,因此我必须使用该Run a Program | VBScript方法。

我的知识:我知道如何处理来自VBA的电子邮件

Sub Sample(MyMail As MailItem)
    Dim strID As String, olNS As Outlook.NameSpace
    Dim olMail As Outlook.MailItem

    strID = MyMail.EntryID
    Set olNS = Application.GetNamespace("MAPI")
    Set olMail = olNS.GetItemFromID(strID)

    '~~> Rest of the code

    Set olMail = Nothing
    Set olNS = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)

我也知道如何收件箱中已有的电子邮件上运行vbscript 。要在OL2000中运行vbscript,必须使用Run A Program并将其指向vbs文件。该Run A Script在OL2000不可用。

我不知道的地方:这就是我需要帮助的地方。如何获取未命中VBS中邮件收件箱的邮件对象。一旦获得对象,就可以执行其余的必要操作。

Jim*_*ena 4

如果本文可信的话,您认为 OL2000 无法从规则运行 VBA 宏是正确的。

以下是我处理传入电子邮件的方法。它确实使用了 VBA,但据我所知,在 VBScript 中没有办法做到这一点。

Private WithEvents Items 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 Items = objNS.GetDefaultFolder(olFolderInbox).Items 
End Sub
Private Sub Items_ItemAdd(ByVal item As Object) 

  On Error Goto ErrorHandler 
  Dim Msg As Outlook.MailItem 
  If TypeName(item) = "MailItem" Then
    Set Msg = item 
    '~~> do something with the new message here
  End If
ProgramExit: 
  Exit Sub
ErrorHandler: 
  MsgBox Err.Number & " - " & Err.Description 
  Resume ProgramExit 
End Sub
Run Code Online (Sandbox Code Playgroud)

应将此代码粘贴到 ThisOutlookSession 模块中,然后重新启动 Outlook。