我发现了几页关于如何抓取电子邮件附件,但不是专门为我所需要的。
偶尔我会收到包含其他几封电子邮件作为附件的电子邮件,而每一封附加的电子邮件都包含PDF,我想把它们放在桌面上的某个地方。
就我所知:
If inSubj("TEST_STRING") Then 'One of my functions from earlier in the code
Dim atmt As Attachment
Dim outAtmt As MailItem 'Outter attachment (mail attachment)
Dim inAtmt As Attachment 'Inner attachment (invoice pdf)
Dim path As String: path = "C:\SOME_PATH"
For Each atmt In msg.Attachments 'Cycle through attachments
If atmt.Type = olEmbeddeditem Then 'If attached is a MailItem
Set outAtmt = atmt 'Outter attchment = said MailItem
For Each inAtmt In outAtmt.Attachments 'Cycle through attachments (the invoices)
inAtmt.SaveAsFile (path & inAtmt.FileName) 'Save file
Next inAtmt
End If
Next atmt
End If请注意,msg是包含其他电子邮件的MailItem。
这也是我第一次使用For每个循环,所以这可能也是一个问题,但是现在我只想得到正确的PDF的逻辑。
我认为问题在于,outAtmt是一个MailItem,,但我不知道其他方法。
发布于 2016-03-06 00:20:55
您需要使用Namespace.GetSharedItem打开保存的MSG文件,然后处理其附件。
如果要避免保存嵌入的消息附件,可以使用赎罪 (我是它的作者)公开RDOAttachment.EmbeddedMsg属性(返回RDOMail对象):
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set rMsg = Session.GetMessageFromID(msg.EntryID)
ProcessAttachments(rMsg)
...
sub ProcessAttachments(Msg)
For Each atmt In rMsg.Attachments 'Cycle through attachments
If atmt.Type = olEmbeddeditem Then
ProcessAttachments(atmt.EmbeddedMsg)
ElseIf atmt.Type = olByValue Then
MsgBox atmt.FileName
'atmt.SaveAsFile "c:\temp\" & atmt.FileName
End If
Next
end subhttps://stackoverflow.com/questions/35805602
复制相似问题