|
本帖最后由 leucine 于 2011-8-19 16:41 编辑
简单写了一下vba,进入outlook后,按alt+f11,在ThisOutlookSession里面粘帖以下代码,记得把宏安全性调成低。
功能:收件箱里收到邮件后,自动分析收件人(包括抄送的),找到第一个包含"@mycompany.com"的收件人,比如staff@mycompany.com。然后在收件箱里建一个以“staff@mycompany.com”命名的文件夹,把邮件移进去。
直接突出显示第一个收件人好像不太好办,只能通过这种方法来达到目的了
outlook2010稍作测试成功。- Private Function newFolder(ByVal folderName As String) As Outlook.Folder
- Dim myNameSpace As Outlook.NameSpace
- Dim myFolder As Outlook.Folder
-
- Set myNameSpace = Application.GetNamespace("MAPI")
- Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
- On Error Resume Next
- Set newFolder = myFolder.Folders.Add(folderName)
- Set newFolder = myFolder.Folders.Item(folderName)
- End Function
- Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
- Dim varEntryIDs As Variant
- Dim myEntryID As Variant
- Dim myItem As MailItem
- Dim varRecpts As Recipients
- Dim myRecpt As Recipient
-
- Dim myAddr As String
- myAddr = ""
-
- Dim myCompanyEmail As String
-
- myCompanyEmail = "@myCompany.com" '设定贵公司邮箱的后缀,通过这个识别哪些邮件是发给贵公司的
-
- varEntryIDs = Split(EntryIDCollection, ",")
- For Each myEntryID In varEntryIDs
- Set myItem = Application.Session.GetItemFromID(myEntryID)
- Set varRecpts = myItem.Recipients
- For Each myRecpt In varRecpts
- If InStr(1, lcase(myRecpt.Address), lcase(myCompanyEmail)) > 0 Then
- myAddr = myRecpt.Address
- Exit For
- End If
- Next
- myItem.Move newFolder(myAddr)
- Next
- End Sub
复制代码 |
|