Problem solve Get help with specific problems with your technologies, process and projects.

LotusScript to extract and move attachments to a Lotus Notes mailbox or file folder LotusScript expert Cregg Hardwick explains how to extract and email attachments to a Lotus Notes mailbox or file folder of your choice using LotusScript code.

I'm trying to find a script that will extract and email attachments to a folder of my choice. I'd also like it...

to print the name of the attachment in the email from which it was removed. Thank you.

I assume that you mean you want to email the attachments to a Lotus Notes mailbox of your choice, as putting them in a folder on the file system is a completely different issue. But, here is how to do both both:

To begin with, creating a directory is easy. LotusScript provides the MkDir command, which takes the pathname of the new folder as a parameter. If appropriate, use the Dir$ command to check to see if the directory (or files within it) already exists.

Now, to extract all attachments, just get a handle to the rich text document and use code similar to the following…

If Not Isempty(rtitem.embeddedObjects) 
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT )  
Call o.ExtractFile ( AttachmentDirectory+
"\" )
End If
End Forall

The test to see if the object is an embedded attachment must be done. Otherwise, the code would trip over any files embedded as OLE objects (which cannot be detached).

Keep in mind that if you have an old pre-R5 Lotus Notes database, attachments may be stored in the documents object collection, instead of those for the rich text field. In theory, the same concepts apply; you just cannot pick a particular rich-text field to extract from. (See the Designer Help for more detail, if needed.)

Do you have comments on this Ask the Expert Q&A? Let us know.

Related information from

  • Tip: Extract attachments and indicate a new location
  • Expert Advice: Extracting and reattaching attachments
  • FAQ: LotusScript advice
  • Reference Center: LotusScript tips and resources

Dig Deeper on Lotus Notes Domino Mailbox Management

  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...