Move incoming email to folders with RegEx in a rule

て烟熏妆下的殇ゞ 提交于 2019-12-12 03:51:54

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!