本文转自: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. Redis 底层数据结构介绍

    Redis 底层数据结构 版本:2.9 支持的数据类型: 字符串 散列 列表 集合 有序集合 字符串 Redis 利用原生的 c 字符串进行了一次封装.封装的字符串叫做简单动态字符串:SDS(simp ...

  2. 《漫画ERP》经典文章摘抄

    1.对企业来说,应用ERP的价值就在于通过系统的计划和控制功能,结合企业的流程优化,有效的配置各项资源,以加快对市场的响应,降低成本,提高效率和效益,从而提升企业的竞争力:

  3. leaflet 结合 geoserver 实现地图属性查询(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  4. IOS弓箭传说的插件开发

    1.导出ipa进行解压后,定位到执行程序archero,ida加载后,发现很多都是sub_xxx开头的. 2.搜索资料后,原来Unity编写的程序,可以使用Il2CppDumper进行符号表还原. 下 ...

  5. Mongdb可视化工具Studio 3T的使用

    一.官网地址 https://studio3t.com/ 二.下载和安装 点击DOWNLOAD即可下载 按照自己电脑系统进行选择,然后填写邮箱和选择行业,第一次登录如果不提交不会下载,下载完成是一个z ...

  6. 如何将本地的项目推送到github

    一.创建密钥 1.本地终端命令行生成密钥 访问密钥创建的帮助文档:https://help.github.com/en/github/authenticating-to-github/generati ...

  7. Linux下设置mysql允许远程连接

    最近在Linux上安装了Mysql,然后在Windows环境下通过Navicat来连接时,出现报错:1045 Access denied for user 'root'@'XXX' (using pa ...

  8. 一起学SpringMVC之RequestMapping详解

    本文以一个简单的小例子,简述SpringMVC开发中RequestMapping的相关应用,仅供学习分享使用,如有不足之处,还请指正. 什么是RequestMapping? RequestMappin ...

  9. C# FlagAttriute 的 小妙招

    FlagAttriute ,指示可将枚举视为位域(即一组标志). 官网中文解说:https://docs.microsoft.com/zh-cn/dotnet/api/system.flagsattr ...

  10. 如何修改PhpStorm快捷键