问题
I am trying to use a regular expression to filter incoming messages by looking at the subject line and if it contains 6 consecutive digits, move it to a particular folder.
I found a script online which I have been trying to modify.
I want to place these emails in a folder called 'AMEX
' which is a subfolder
of the main Inbox.
Sub filter(Item As Outlook.MailItem)
Dim ns As Outlook.NameSpace
Dim MailDest As Outlook.Folder
Set ns = Application.GetNamespace("MAPI")
Set Reg1 = CreateObject("VBScript.RegExp")
Reg1.Global = True
Reg1.Pattern = "([\d][\d][\d][\d][\d][\d])"
If Reg1.Test(Item.Subject) Then
Set MailDest = ns.Folders("Inbox").Folders("AMEX")
Item.Move MailDest
End If
End Sub
回答1:
your problem is with the folder name replace Set MailDest = ns.Folders("Inbox").Folders("AMEX")
with this line
Set MailDest = ns.Folders("enteryouraccountname@yourhost.com").Folders("Inbox").Folders("AMEX")
and dont forget to put in your account name
回答2:
You could also set it like this.
Set MailDest = ns.GetDefaultFolder(olFolderInbox).Folders("AMEX")
GetDefaultFolder Method
来源:https://stackoverflow.com/questions/39152007/move-incoming-email-to-folders-with-regex-in-a-rule