自动提取Exchange Server上的电子邮件附件

创build了一个Exchange电子邮件帐户,通过它我将每天收到三封不同的Excel附件的电子邮件。

每个Excel附件必须保存在三个不同文件夹中的一个中。

可以将Exchange Serverconfiguration为自动执行此操作,还是必须编写脚本来监视帐户是否有新电子邮件?

我相信这是一个Exchange 2007服务器。

我目前正在使用一个python脚本来达到这个目的,它会login到mailbow中,然后下载附件和备份电子邮件,这些mods可能很适合你的需求,如果你愿意,可以用py2exe编译它。 这是代码 。

PS:这个代码是由Suresh Kesmar写的(所有学分都是他的)Orignaly;)

恐怕你必须用脚本来完成,因为Outlook喜欢保护你自己。 以下说明来自这里 。 我修改了一些适用于您的Excel电子表格。 请记住,如果他们来自Excel 2007,则必须在脚本中使用“xlsx”作为文件扩展名。

  1. 打开Outlook。 我正在使用Outlook 2007,但这也应该在Outlook 2003中工作。转到工具>macros> Visual Basic编辑器。
  2. 将项目文件夹高亮显示(在左上方的PROJECT窗格中,我只使用默认项目),右键单击并select“插入”>“模块”。 将以下代码复制并粘贴到编辑器的主窗口中:
[vb]Sub SaveAttachmentsToDisk(Item As Outlook.MailItem) Dim olkFolder As Outlook.MAPIFolder, _ olkAttachment As Outlook.Attachment, _ objFSO As Object, _ strRootFolderPath As String, _ strFilename As String, _ intCount As Integer 'Change the following path to match your environment strRootFolderPath = "z:\www\departments\webreports\" Set objFSO = CreateObject("Scripting.FileSystemObject") Set olkFolder = Application.ActiveExplorer.CurrentFolder If Item.Attachments.Count > 0 Then For Each olkAttachment In Item.Attachments If objFSO.GetExtensionName(LCase(olkAttachment.FileName)) 

=“xls”然后

 strFilename = olkAttachment.FileName intCount = 0 Do While True If objFSO.FileExists(strRootFolderPath & 

strFilename)然后

 intCount = intCount + 1 objFSO.deletefile (strRootFolderPath & strFilename) Else Exit Do End If Loop olkAttachment.SaveAsFile strRootFolderPath & strFilename End If Next End If Set objFSO = Nothing Set olkAttachment = Nothing Set olkFolder = Nothing End Sub[/vb] 
  1. 您将需要确保您具有适当的安全级别设置为了正确处理脚本。 在Outlook中,转到工具>macros>安全。 我select了没有安全检查的macros。 这可能对您的环境造成太大的限制; 如果是这样,请尝试下一个最高设置。

  2. 创build一个新的Outlook规则(工具>规则和警报)以反映您的更改。 我的规则查找来自特定电子邮件地址的新邮件,并具有一个附件(我想要移动的Web文件),将邮件移动到特定文件夹(以便我可以备份邮件/附件),然后运行上面的模块/脚本将Web文件移动到适当的samba共享。 这是我的规则说明看起来像:

 Apply this rule after the message arrives from [email protected] and which has an attachment and on this machine only move it to the WEBBACKUP folder and run Project1.SaveAttachmentsToDisk 
  1. 点击应用并确定保存您的规则。 几个注意事项:这是客户端规则,所以您必须保持Outlook运行,以便规则处理。 此外,代码将覆盖与附件具有相同名称的任何文件(在我的情况下,在目标samba共享中)。 如果您只想复印,可以在附件名称后附加一个数字。 为此,请replace以下代码行:

objFSO.deletefile(strRootFolderPath&strFilename)

“&olkAttachment.FileName”的strFilename =“Copy(”&intCount&“)