Directing emails of one account to multiple folders by Outlook Rules

时间:2015-07-31 19:25:19

标签: vba outlook-vba outlook-2010

I hope there is someone who have an idea about this issue.

I want to archive a sender's emails(for example send form : test@tect.com) to more than one folder in outlook concurrently by using automatic rule function.

Is this possible?

1 个答案:

答案 0 :(得分:0)

是的,可以借助脚本规则和 vba 代码。

以下代码在识别的邮件到达时创建一个副本,然后将复制邮件移动到多个文件夹。

Option Explicit
Public Sub MoveItems(olItem As Outlook.MailItem)
    Dim olApp As New Outlook.Application
    Dim olNameSpace As Outlook.NameSpace
    Dim olInbox As Outlook.MAPIFolder
    Dim olDestFolder As Outlook.MAPIFolder
    Dim olItems As Outlook.Items
    Dim CopyItem As Object

    Set olNameSpace = olApp.GetNamespace("MAPI")
    Set olInbox = olNameSpace.GetDefaultFolder(olFolderInbox)
    Set olItems = olInbox.Items

    '// loop
    While TypeName(olItem) <> "Nothing"
        Set olDestFolder = olInbox.Folders("TEMP1") 'Folder
        Set CopyItem = olItem.copy
        olItem.Move olDestFolder

        Set olDestFolder = olInbox.Folders("TEMP2") 'Folder
        olItem.Move olDestFolder

        Set olDestFolder = olInbox.Folders("TEMP3") 'Folder
        olItem.Move olDestFolder

        '// Add more folders here

        Set olItem = olItems.FindNext
    Wend

    Set olNameSpace = Nothing
    Set olInbox = Nothing
    Set olDestFolder = Nothing
    Set olItems = Nothing
    Set olItem = Nothing
    Set CopyItem = Nothing
End Sub