2013-04-30 119 views
1

我从未遇到过这个问题,但我无法获得电子邮件上文件附件的句柄。我有代码可以搜索文档的嵌入对象或搜索字段的嵌入对象 - 他们都没有返回文件。我可以在电子邮件中看到该文件,并且可以看到包含文件附件的$ FILE字段。LotusScript无法从电子邮件中获取文件附件

下面是代码:

Function FileDetachFiles(doc As NotesDocument, fieldName As String, getFromField As Integer) As Variant 

    On Error Goto ProcessError 

    Dim s As NotesSession 
    Dim db As NotesDatabase 
    Dim rtItem As NotesRichTextItem 
    Dim fileToExtract As String 
    Dim fileName As String 
    Dim fileArray() As String 
    Dim message As String 
    Dim embedObjects As Variant 
    Dim attachFile As Integer 
    Dim x As Integer 

    Set s = New NotesSession  
    Set db = s.CurrentDatabase 
    Const fileImport = "C:\" 
    attachFile = False 

    'Let's see if there are attached files... 
    If getFromField = True Then 
     'Locate field and get files... 
     If doc.HasEmbedded Then 
      If doc.HasItem(fieldName) Then   
       'Set the first field... 
       Set rtItem = doc.GetFirstItem(fieldName) 
       embedObjects = rtItem.EmbeddedObjects 
       If Isarray(embedObjects) Then 
        Forall Files In rtItem.EmbeddedObjects 
         If Files.Type = EMBED_ATTACHMENT Then 
          fileName = Files.Source 
          fileToExtract = fileImport & fileName 
          Redim Preserve fileArray(x) 
          fileArray(x) = fileToExtract 
          x = x + 1 
          Call Files.ExtractFile(fileToExtract) 
          attachFile = True    
         End If   
        End Forall 
       End If 
      End If 
     End If 
    Else  
     x = 0  
     'Go through doc looking for all embedded objects... 
     If doc.HasEmbedded Then 
      Forall o In doc.EmbeddedObjects 
       If o.Type = EMBED_ATTACHMENT Then 
        fileName = o.Name 
        fileToExtract = fileImport & fileName 
        Call o.ExtractFile(fileToExtract) 
        Redim Preserve fileArray(x) 
        fileArray(x) = fileToExtract 
        x = x + 1 
        attachFile = True  
       End If  
      End Forall 
     End If  
    End If 

    If attachFile = True Then  
     FileDetachFiles = fileArray 
    End If 

    Exit Function 
ProcessError: 
    message = "Error (" & Cstr(Err) & "): " & Error$ & " on line " & Cstr(Erl) & " in GlobalUtilities: " & Lsi_info(2) & "." 
    Messagebox message, 16, "Error In Processing..." 
    Exit Function 
End Function 

我尝试了上述两个程序 - 经过$ FILE美体字段名,以及搜索文档。它没有找到任何文件附件。

我甚至试过这样: Extracting attachments as MIME using LotusScript

哪个没有找到该文件的任何MIME。

我从来没有遇到过这个问题 - 任何想法都会很棒。

谢谢!

回答

5

我以前曾经这样做过,但不幸不记得,它来自哪里,它可能不得不采用来自Domino网站的V2样式附件...... 尝试评估(@AttachmentNames)以获取包含Variant的变体所有附件的名称。然后用Forall循环遍历它并尝试使用NotesDocument.getAttachment(strLoopValue) - Function来获取附件的句柄。 如需进一步信息阅读here并按照页面上的链接,特别是this one

代码将是这样的:

Dim doc as NotesDocument 
Dim varAttachmentNamens as Variant 
Dim object as NotesEmbeddedObject  

REM "Get the document here" 
varAttachmentNames = Evaluate("@AttachmentNames" , doc) 
Forall strAttachmentName in varAttachmentNames 
    Set object = doc.GetAttachment(strAttachmentName) 
    REM "Do whatever you want..." 
End Forall 
+0

这工作 - 谢谢!这里是我想出了最终代码: – Dan 2013-04-30 17:38:30

+1

attachNames =评估( “@AttachmentNames”,DOC) \t FORALL值在attachNames \t \t attachName =值 \t \t设置对象= doc.GetAttachment(attachName) \t \t如果object.Type = EMBED_ATTACHMENT然后 \t \t \t文件名= object.Name \t \t \t fileToExtract = fileImport&文件名 \t \t \t呼叫object.Extra ctFile(fileToExtract) \t \t \t REDIM保留fileArray(X) \t \t \t fileArray(X)= fileToExtract \t \t \t X = X + 1 \t \t结束如果\t \t \t FORALL完 – Dan 2013-04-30 17:39:44