本文转自: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. hadoop集群搭建教程

    1. 相关软件准备: VMware-workstation-full-15.0.4-12990004.exe CentOS-7-x86_64-DVD-1810.iso jdk-8u231-linux- ...

  2. Gemini.Workflow 双子工作流高级教程:对外API控制引擎:总述

    前言: 双子工作流提供了一套对外的API,用于控制整体系统运转,下面就来看看介绍,其实很简单的. 对外API控制引擎总介: Gemini.Workflow 双子工作流,对外提供的API,都在Gemin ...

  3. RedisSession (自定义)

    RedisSession (自定义) 疯狂创客圈 Java 高并发[ 亿级流量聊天室实战]实战系列 [博客园总入口 ] 架构师成长+面试必备之 高并发基础书籍 [Netty Zookeeper Red ...

  4. Ansible-playbook之定义变量

    1.引用变量 # 变量引用方式 "{{ }}" 2.定义变量 (vars) - hosts: web # 定义变量 vars: - play_var: This_is_play_v ...

  5. Spring 关于ResponseBody注解的作用

    //responseBody一般是作用在方法上的,加上该注解表示该方法的返回结果直接写到Http response Body中,常用在ajax异步请求中, //在RequestMapping中 ret ...

  6. 物联网架构_对AWS的Greengrass的认识与理解

    物联网架构_对AWS的Greengrass的认识与理解 一,前言: 这段时间有许多的收获,分析,还有总结,其中包括新系统的设计与开发,以及其中新技术的踩坑等等等. 但是最近真的很忙,项目的推进,面试工 ...

  7. 使用kubernetes的cronjob定时备份mysql数据库

    1.创建cronjob的文件 CronJob所描述的,正是定时任务. 在给定时间点只运行一次 在给定时间点周期性地运行 一个 CronJob 对象类似于 crontab (cron table)文件中 ...

  8. Execl数据上传到数据库

    =============================================================asp.net================================ ...

  9. MySQL能否授予查看存储过程定义权限给用户

    在其他RDBMS中,可以将查看某个存储过程(PROCEDURE)定义的权限给某个用户,例如在SQL Server中,可以单独将查看ProcedureName定义的权限授予UserA GRANT VIE ...

  10. s3c2440裸机-内存控制器(三、norflash初始化-时序设置)

    1.norflash与2440的硬件连接 2.初始化nor,配置nor时序 1.如图是S3C2440的内存控制器的可编程访问周期读写时序,里面的时间参数要根据外部设备的性能进行配置,这里先列出时间参数 ...