更改Application_NewMail事件中的邮件项目 [英] Change mail item within the Application_NewMail Event

查看:230
本文介绍了更改Application_NewMail事件中的邮件项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了处理传入邮件,我覆盖了Application_NewMail()函数.

I overwrite the Application_NewMail() function, in order to do something with the incoming mail.

如果传入邮件符合给定条件,那么我要执行olMail.Subject ="Mymark" + olMail.Subject或我执行olMail.Categories ="MyMark".

If the incoming mail matches given condition, then I want to do olMail.Subject = "Mymark" + olMail.Subject or I do olMail.Categories = "MyMark".

但是我似乎为时已晚,因为邮件已经在收件箱中,并且不会传播这些更改.

But it seems that I do this too late, because the mail is already in inbox and theese changes are not propagated.

Private Sub Application_NewMail()
Dim olFld As Outlook.MAPIFolder
Set olFld = Outlook.Session.GetDefaultFolder(olFolderInbox)
olFld.Items.Sort "[ReceivedTime]", False   
Dim olMail As Outlook.MailItem
Set olMail = olFld.Items.GetLast
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim doc As Variant
Set olMail = olFld.Items.GetLast        
Set Reg1 = New RegExp
With Reg1       
    .Pattern = "[^0] (x ERROR)"
    .Global = True
End With 
If Reg1.Test(olMail.Body) Then
    Set M1 = Reg1.Execute(olMail.Body)
    For Each M In M1
          olMail.Subject    = "mymark" + olMail.Subject
          olMail.Categories = "XYZ"             
    Next
End If      
End Sub

推荐答案

使用

当新消息到达收件箱时,并且在发生客户端规则处理之前,将触发NewMailEx事件.您可以使用EntryIDCollection数组中返回的Entry ID来调用NameSpace.GetItemFromID方法并处理该项目.

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)

    Dim Item As Object
    Set Item = Session.GetItemFromID(EntryIDCollection)
        Item.Subject = "mymark " & Item.Subject
        Item.Save

        Debug.Print Item.Subject

End Sub

这篇关于更改Application_NewMail事件中的邮件项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆