2013-04-30 130 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

相關問題