LotusScript cannot get file attachment from email
lotus-domino, lotus-notes, lotusscript, mime, richtext
Solution
I had that before, but unfortunately do not remember, where it comes from, it might have to do something with V2- Style Attachments coming from Domino Websites... Try Evaluate( @AttachmentNames ) to get a Variant containing the names of all attachments. Then loop through this with a Forall- loop and try the NotesDocument.getAttachment( strLoopValue ) - Function to get a handle to the attachment. For further info read here and follow the links on that page, especially this one
Code would be something like this:
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
Problem
I had never run into this problem, but I cannot get a handle on a file attachment on an email. I have code that can either search the document for Embedded Objects or search a field for Embedded Objects -- neither of them are returning the file. I can see the file on the email and I can see the $FILE field which contains the file attachment. Here is the code: ``` 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 ``` I tried both routines above -- passing the $FILE and Body field names, as well as searching the document. It does not find any file attachments. I even tried this: Extracting attachments as MIME using LotusScript Which did not find any MIME on the document. I have never run into this problems -- any ideas would be great. Thanks!