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

标签 vbscript outlook

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

Outlook 版本:Outlook 2000

说明:我无法为此使用 VBA,因为我相信 Outlook 2000 不允许您从规则向导运行 VBA 脚本,因此我必须使用 运行程序 | 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

我还知道如何在收件箱中已经的电子邮件上运行 vbscript。要在 OL2000 中运行 vbscript,您必须使用运行程序并将其指向 vbs 文件。 运行脚本在 OL2000 中不可用。

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

最佳答案

如果 this article 可信的话,您认为 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

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

关于vbscript - 使用 vbscript 处理传入的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11471528/

相关文章:

delphi - 在 Outlook 中生成新消息并显示为模式

outlook - HTML 电子邮件中的前置文本

excel - 如何在 VBA 中根据我的文本创建表格

batch-file - 如何在批处理文件中设置参数等于VB6变量

vba - 在 Windows 文件夹中保存选定的 Outlook 电子邮件的宏

html - 从 Outlook 复制/粘贴后,剪贴板中的 html 末尾有什么奇怪的字符

vbscript - 创建VBScript函数时出现问题

function - vbscript函数语法错误

javascript - 打印网页没有任何提示?使用 javascript 或 jquery 或 vbscript

javascript - HTML/PHP 页面中的 VBScript