VBA编程实现邮件自动分类
通过脚本,接收邮件后,自动移动到相应的文件夹。
- 首先在收信箱下创建三个文件夹:HR、IT和Software。
- 其次通过GetFolder(strFolderPath As String)方法获取文件夹对象。
- 然后根据CheckInContact(mailAdress As String)方法获取发信人的部门信息。
- 最后根据部门信息,移动邮件到相应的文件夹。
Sub AutoMove(Item As Outlook.mailItem)
Dim var As Variant
var = ClassifyMail(Item)
Set Item = Nothing
End Sub
Public Function ClassifyMail(Item As Outlook.mailItem)
'move mail to related folder
Dim objApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim srcFolder As Outlook.Folder
Dim dstFolder As Outlook.Folder
Dim srcFolderPath As String
Dim dstFolderPath As String
Dim i As Integer
On Error GoTo last
Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
srcFolderPath = "Outlook\收件箱"
Set srcFolder = GetFolder(srcFolderPath)
Select Case