Printing attachments in the protected area of a form.

Posted on 2006-05-18
Last Modified: 2013-12-18
We receive Faxes from a Right Fax server into our Lotus Notes inbox.  We need an agent that will print the fax attachments without having to individually open each email.  The problem, however, is that the faxes are not attached to the email "Body" but are in a "protected area of the form", thus, the normal method of creating a rich text navigator will not work.  The below code being an example:

                Dim rtitem As notesrichtextitem
     If doc Is Nothing Then Exit Sub
     If doc.HasItem ("Body") = False Then Exit Sub                                                            
     Set rtitem = doc.GetFirstItem( "Body" )      
     If ( rtitem.Type = RICHTEXT ) = False Then Exit Sub
     If Isempty(rtitem.EmbeddedObjects) Then Exit Sub
     Forall o In rtitem.EmbeddedObjects
          If ( o.Type = EMBED_ATTACHMENT ) Then
               Call PrintAttachment (o)
          End If
     End Forall

I do not know how to get at the attachments if they are not in the email body.  When I throw the Lotus Script in debug, I can see the attachments in the document as $FILE items, but they are NotesItems, not rich text items, which leaves me without the embeddedobjects method.  I am at a loss for what to do?  Thank you.
Question by:druss23
    LVL 18

    Expert Comment

    Try the document embedded objects method.. with $file you can get the filename, the document embedded objects will collect all $file, and you can extract from there or launch.

    Search on NotesDocument properties, I think (Sorry, not at a Notes Computer today)
    LVL 18

    Expert Comment


    Sub Initialize
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Set db = New NotesDatabase( "SanFrancisco", "hill.nsf" )
      Set view = db.GetView( "All Documents" )
      Set doc = view.GetLastDocument
      If doc.HasEmbedded Then
        Forall o In doc.EmbeddedObjects
          Messagebox( o.Name )
        End Forall
        Messagebox "No embedded objects found"
      End If
    End Sub

    from the Embedded Objects property of NotesDocument

    Author Comment

    Thank you for the reply.  I receive a type mismatch when running the above code on the Forall line.  I believe this is because the embeddedobjects method in the notesDocument class does not deal with File attachments, everything we receive is a file attachment, it is simply not attached in the body.  From the Notes help about this method in NotesDocument:
    Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments.  
    We are forced to use the embeddedobjects property in NotesRichTextItem, since it is the only one that returns file attachments types.
    LVL 18

    Expert Comment

    No, i don't believe that's the reason, I copied a sample file from the Designer Help, and they typically don't instantiate objects or properties.  Nor do they check for the existance of the properties. :)

    So, for instance,
    You would need sonething like this:

    Dim session as New Notessession
    Dim db as Notesdatbase
    set db = session.currentdatbase
    dim view as Notesview
    set view = db.getView("my viewname")
    if view is nothing then
     msgbox "Sorry, view not found"
      exit sub
    end if
    set doc = view.getfirstdocument
    while not doc is nothing
       if doc.hasEmbedded then
             forall o in doc.embeddedObjects
                 If ( o.Type = EMBED_ATTACHMENT ) Then
                        Call o.ExtractFile( "c:\samples\" & o.Source )
                  end if
    end forall

    set doc = view.getNextDocument(doc)

    You need to adjust it.  Are you lotusscript capable?  If not, I will adjust for you, but am not at a Notes computer right now.  

    I believe it the instructions for the embedded object that you're seeing is for java, not for the NotesDocument class in LotusScript.  I say this, because I use the doc embedded to detach all attachments from a document when they're not embedded in the RichText field.  So, you can use the rtfield, or the plain doc attachments.  You could probably use the doc.getAttachment( using the $file = filename of the attachment)

    Here's another way:

    when I get home, I will see what I can do to pull a snippet for you.

    LVL 18

    Accepted Solution

    Ok here is the exact quote:  Unlike the EmbeddedObjects property in NotesRichTextItem, this property does not include file attachments, nor OLE/1 objects created in Notes Release 3.  <<< NOtes Release 3 is the operative phrase here.

    Here is a quick and dirty snippet that I had:  (paste into an agent, and run on selected documents)

    Sub Initialize
          'Add your correct filepath here..........................
          Const FILEPATH = "C:\Temp\"
          Const DEFAULTEXT = ".txt"
          Dim Session As New NotesSession
          Dim db As NotesDatabase
          Set db = session.currentdatabase
          Dim doc As NotesDocument
          Dim coll As NotesDocumentCollection
          Set coll = db.unprocesseddocuments
          Dim count As Integer
          Dim NumAttachments As Variant
          Dim attachmentNames As Variant
          Dim strAttachments As String
          Dim formatString As String, filename As String
          Dim object As NotesEmbeddedObject
          Const NumMacro = {@Attachments}
          Const NameMacro = {@AttachmentNames}
          If coll.count <1 Then Exit Sub
          Set doc = coll.getfirstdocument
          While Not doc Is Nothing
                With doc
                      NumAttachments = Evaluate(NumMacro,Doc)
                      AttachmentNames = Evaluate(NameMacro,Doc)                  
                      If doc.HasEmbedded Then
                            If Isarray(attachmentNames) Then
                                  Forall a In attachmentNames
                                        If Len(a)<>"" Then
                                              Set object = doc.GetAttachment(a)
                                              If Not object Is Nothing Then
                                                    'Making sure I don't overwrite the files, you can do this with a date, too.
                                                    count = count +1
                                                    FileName = object.Source
                                                    If Instr(1, filename, ".", 5)>0 Then
                                            'the attachment has a file extension leave as is.      
                                                          formatString = FILEPATH + Format(count,"00") + "_" + filename
                                                          'I'm adding a file extension...
                                                          formatString = FILEPATH  + Format(count,"00") + "_" + filename + DEFAULTEXT
                                                    End If                                                
                                                    Call object.ExtractFile(formatString)            
                                                    strAttachments = strAttachments + filename + Chr(13)
                                                    Print "Detaching " + formatstring + " ..."
                                                    'Optional you can delete the attachement and save the file
                                                    'However, don't do this if your view collects on attachments else
                                                    'you'll lose the pointer
                                                    'Call object.Remove
                                                    ' True, False, True
                                                    '............................................End Optional
                                              End If
                                        End If
                                  End Forall
                            End If
                      End If
                End With
                Redim NumAttachments(0)
                Redim AttachmentNames(0)            
                Set doc = coll.GetNextDocument(doc)
          If Not coll Is Nothing Then Set coll = Nothing
          Msgbox {Detached: } + Cstr(count) + { attachments.} + Chr(13) +_
    End Sub

    Author Comment

    The operative phrase applies to the second condition (the OLE object).  This is further illustrated in the example section of this same page, which is a little more explicit and not as ambiguously worded.  From the example section:

    EmbeddedObjects does not return the Ami Pro document because the object was created in Notes Release 3. It does not return castle.bmp because castle.bmp is a file attachment.

    Your code above works (using the GetAttachment method rather than the EmbeddedObject method), and this is what we ultimately will use!  Thank you for your help.
    LVL 18

    Expert Comment

    Yeah, you have to jump through hoops (some minor ones) to grab the ole object on the document, when I was in a hurry, I did this snippet to grab it fast.  Figured it would be of assistance to you, too. :)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
      In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now