【发布时间】:2022-05-04 04:30:50
【问题描述】:
好的,所以我有一个脚本通过我的 Outlook 收件箱寻找特定的标题字符串。这对于直接在我的收件箱中的电子邮件非常有用。现在我正在尝试将此检测扩展到包含其他电子邮件作为附件的电子邮件。我花了很多时间研究这个,我似乎找不到直接访问电子邮件附件的正确方法。我最终所做的是将附件保存到光盘,然后使用 CreateItemFromTemplate 将其读回。我发现这是一个杂乱无章的解决方案,我希望这里的人可以帮助我找到一种更优雅的方法来做到这一点,我可以绕过另存为 CreateItemFromTemplate 并直接从附件创建一个项目对象。这是我为此编写的概念证明脚本:
Const olFolderInbox = 6
Const olMail = 43
Const olEmbeddeditem = 5
Const PropName = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
Set app = CreateObject("Outlook.Application")
set objNamespace = app.GetNamespace("MAPI")
set objInboxItems = objNameSpace.GetDefaultFolder(olFolderInbox).items
wscript.echo "Have your inbox open checking for fish tests or emails as attachments"
for each objItem in objInboxItems
if objItem.Class = olMail then
with objItem
strHeader = .PropertyAccessor.GetProperty(PropName)
iLoc1 = instr(1,strHeader,"X-Testing",1)
if iLoc1 > 0 then
wscript.echo "mytest. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
end if
iLoc1 = instr(1,strHeader,"X-PHISHTEST",1)
if iLoc1 > 0 then
wscript.echo "Go Fish. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
end if
if .attachments.count > 0 then
set objAttachment = .attachments.item(1)
if objAttachment.type = olEmbeddeditem then
wscript.echo "Has Attachment. From: " & .Sender & " at: " & .ReceivedTime & " subjet: " & .Subject
wscript.echo " - Filename: " & objAttachment.Filename
objAttachment.SaveAsFile ("c:\temp\TempEmail.msg")
set objExtMsg = app.CreateItemFromTemplate("c:\temp\TempEmail.msg")
strExtHeader = objExtMsg.PropertyAccessor.GetProperty(PropName)
iLoc1 = instr(1,strExtHeader,"X-Testing",1)
if iLoc1 > 0 then wscript.echo " ++ This is a plain test message"
end if
end if
end with
end if
next
wscript.echo "That's all folks" `
【问题讨论】:
-
可以使用 CDO 渲染 ObjectRenderer 对象将附件对象渲染为 HTML 超文本。要指定这一点,请将对象渲染器的 DataSource 属性设置为 Attachment 对象本身。可以使用 RenderProperty 方法呈现的各个属性在 Attachment 对象属性描述中指明。来自msdn.microsoft.com/en-us/library/ms526700(v=exchg.10).aspx
-
我特别不希望渲染对象,如果渲染消息,它实际上会对我的 POC 产生负面影响。我正在寻找访问电子邮件标头并检查是否存在特定标头,无论是在邮件本身还是在附加的电子邮件中。
-
你读了吗。它允许您访问要呈现的数据。
标签: vbscript outlook email-attachments