更改Application_NewMail事件中的邮件项目 [英] Change mail item within the Application_NewMail Event
本文介绍了更改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
推荐答案
查看全文