首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >附件中的附件

附件中的附件
EN

Stack Overflow用户
提问于 2016-03-04 20:38:34
回答 1查看 152关注 0票数 2

我发现了几页关于如何抓取电子邮件附件,但不是专门为我所需要的。

偶尔我会收到包含其他几封电子邮件作为附件的电子邮件,而每一封附加的电子邮件都包含PDF,我想把它们放在桌面上的某个地方。

就我所知:

代码语言:javascript
复制
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,,但我不知道其他方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-06 00:20:55

您需要使用Namespace.GetSharedItem打开保存的MSG文件,然后处理其附件。

如果要避免保存嵌入的消息附件,可以使用赎罪 (我是它的作者)公开RDOAttachment.EmbeddedMsg属性(返回RDOMail对象):

代码语言:javascript
复制
  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 sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35805602

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档