本文转自:http://www.outlookcode.com/d/code/quarexe.htm

To quarantine application file attachments

This Outlook VBA code sample monitors the Inbox folder for new items, looks for messages with attached files with the extensions listed in the USER OPTIONS section,

and moves such messages to an Inbox\Quarantine folder for later review, creating the folder if it doesn't exist.

Place this code in the ThisOutlookSession module so that it runs when Outlook starts.

Code Sample

Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
Set objNS = Nothing
End Sub Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
Dim objAttFld As MAPIFolder
Dim objInbox As MAPIFolder
Dim objNS As NameSpace
Dim strAttFldName As String
Dim strProgExt As String
Dim arrExt() As String
Dim objAtt As Attachment
Dim intPos As Integer
Dim I As Integer
Dim strExt As String ' #### USER OPTIONS ####
' name of Inbox subfolder containing messages with attachments
strAttFldName = "Quarantine"
' delimited list of extensions to trap
strProgExt = "exe, bat, com, vbs, vbe" On Error Resume Next
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objAttFld = objInbox.Folders(strAttFldName)
If Item.Class = olMail Then
If objAttFld Is Nothing Then
' create folder if needed
Set objAttFld = objInbox.Folders.Add(strAttFldName)
End If
If Not objAttFld Is Nothing Then
' convert delimited list of extensions to array
arrExt = Split(strProgExt, ",")
For Each objAtt In Item.Attachments
intPos = InStrRev(objAtt.FileName, ".")
If intPos > Then
' check attachment extension against array
strExt = LCase(Mid(objAtt.FileName, intPos + ))
For I = LBound(arrExt) To UBound(arrExt)
If strExt = Trim(arrExt(I)) Then
Item.Move objAttFld
Exit For
End If
Next
Else
' no extension; unknown type
Item.Move objAttFld
End If
Next
End If
End If On Error GoTo
Set objAttFld = Nothing
Set objInbox = Nothing
Set objNS = Nothing
Set objAtt = Nothing
End Sub

Notes

This code is no substitute for a good virus scanner.

In most versions of Outlook, application file types such as .exe are already blocked by the Outlook Email Security Update, so this code won't have any effect.

You could adapt this technique to detect files of any particular type and perform specific processing on them. Don't forget that you must save an attachment first (Attachment.SaveAsFile) before you can access it with the methods appropriate for that file's application.

More Information

[转]VBA Check if an outlook folder exists; if not create it的更多相关文章

  1. C# IO流 File.Exists,Directory.Exists, File.Create,Directory.CreateDirectory

    void Start() { CreateDirectory(); CreateFile(); } //平台的路径(封装起来的一个属性,这不是一个方法) public string path { ge ...

  2. C#文件帮助类FoderHelper

    using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; us ...

  3. MFC: Create Directory

    Original link: How to check if Directory already Exists in MFC(VC++)? MSDN Links: CreateDirectory fu ...

  4. C# 文件帮助类

    using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; us ...

  5. sharepoint 2010 记录管理 对象模型

    首先说一下什么是记录管理:这里有详细的说明 在 网站设置->网站集管理->网站集功能 中启用 “现场记录管理” 启用现场记录管理后在 网站管理 中多了2个功能“内容管理器设置” 和“内容管 ...

  6. openldap数据备份还原

    数据备份[root@Server ~]# slapcat -n 2 -l /root/ldapbackup_ilanni.ldif脚本 ----- #!/bin/bash # 备份脚本 PATH=&q ...

  7. Mysql:自动化备份

    简介 在这个数据为王的时代,数据的备份十分重要,这里就分享一篇mysql数据库自动备份的脚本(是从网上搜到的),其将配置文件和备份脚本分离,提高了安全性,脚本风格规范严谨,分享给大家希望对需要的小伙伴 ...

  8. 为 Memcached 构建基于 Go 的 Operator 示例

    Operator SDK 中的 Go 编程语言支持可以利用 Operator SDK 中的 Go 编程语言支持,为 Memcached 构 建基于 Go 的 Operator 示例.分布式键值存储并管 ...

  9. 用 OUTLOOK VBA 生成 自定义文件夹 邮件列表

    Option Explicit Sub TestFolder() 'Dim outlookapp, myitem, myfolder 'Dim mailcounts As Integer ' ' 'S ...

随机推荐

  1. Support URL

    如您有任何疑问或者建议,请通过以下方式与我们取得联系,我们会尽快响应您的反馈: 邮箱:eighteyes_cn@163.com

  2. 元类, pymysql

    元类, pymysql 一.元类 自定义元类 ''' 1.什么是元类? - 类的类就是type,其实type就是元类 2.元类的作用? 3.如何创建元类以及使用? ''' # # 1.一切皆对象 # ...

  3. centos_mysql 安装脚本

    #!/bin/bash env echo "Download msyql5.7 rpm..." sudo yum install wget wget -i -c http://de ...

  4. 主说明:自动Undo管理的故障排除指南(Doc ID 1579081.1)

    Master Note: Troubleshooting guide for Automatic Undo Management (Doc ID 1579081.1) APPLIES TO: Orac ...

  5. Key Management: Hardcoded Encryption key 密钥管理:硬编码加密密钥

  6. (转)两种高效过滤敏感词算法--DFA算法和AC自动机算法

    原文:https://blog.csdn.net/u013421629/article/details/83178970 一道bat面试题:快速替换10亿条标题中的5万个敏感词,有哪些解决思路? 有十 ...

  7. dedecmsV5.7 百度编辑器ueditor 多图上传 在线管理 排序问题

    问题:dedecms后台百度编辑器ueditor的多图上传-在线管理的图片排序有问题,想把这个顺序调成按照文件修改时间倒序来展示 解决方法: 1.打开/include/ueditor/php/acit ...

  8. jeecg代码生成器配置及常见问题

    jeecg_database.properties 以mysql为例: diver_name=com.mysql.jdbc.Driver url=jdbc:mysql://192.168.*.*:33 ...

  9. Mac环境下执行npm install报权限错误解决办法

    1. 一般情况 sudo npm install 注:这相当于windows系统中的 以管理员身份执行,加上sudo后会要求你输入苹果账号密码,而且在输入的时候是没有字符提示的,密码输入完直接按回车就 ...

  10. Linux基础命令---ntpstat显示时间服务器同步

    ntpstat ntpstat指令用于显示本机上一次和服务器同步时间的情况. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.   1.语法 ntpstat   2 ...