Manage Learn to apply best practices and optimize your operations.

Copy email and attachments to a Lotus Notes database using LotusScript

Learn how to add a LotusScript-generated button to users' email that will copy an entire email, including attachments, to a Lotus Notes database with a single click.

This LotusScript code will reside in a button in Lotus Notes users' email. One click will allow them to copy an entire email, including attachments, to a Lotus Notes database. This method is much easier than the alternative of forwarding or copying and pasting email.

The QueryClose code at the end makes the new Lotus Notes document a response of the document selected in the target database. The view, "AdminCustomer UNID," lists all entries in alphabetical order.

More LotusScript resources:
FAQ: LotusScript

LotusScript Learning Guide

LotusScript Reference Center

 Sub Click(Source As Button)
 Dim workspace As 
New NotesUIWorkspace
 Dim picklist As Variant
 Dim messagelist As String
 Dim originDoc As NotesDocument
 Dim custDoc As NotesDocument
 Dim resDoc As NotesDocument
 Dim resUIDoc As NotesUIDocument
 Dim originUIDoc As NotesUIDocument
 Set originUIDoc = 
 Set originDoc = originUIDoc.Document
 'First, select the 
customer we are going to attach this to  
 picklist = workspace.PickListStrings
"database.nsf", "AdminCustomer UNID", 
"Database Title", "Please select the customer.", 5 )
 Forall plist In picklist
  messagelist =
 messagelist & plist
 End Forall
 'Second, we are going to 
compose an Email doc
 Dim bidDB As 
New NotesDatabase("servername","database.nsf")
 Set emailDoc = New NotesDocument(bidDb)
 emailDoc.Form = "tmpResponse" 
 emailDoc.Topic = "Email"
 emailDoc.Subject = "Incoming - 
" & originDoc.Subject(0)
 emailDoc.ResDate = 
 emailDoc.ParUNID = messagelist
 Dim rtitem As NotesRichTextItem
 Set rtitem = 
New NotesRichTextItem( emailDoc, "resRich")
 Dim success As Variant
 success = 
originDoc.RenderToRTItem( rtitem )
 Set emailUIDoc = 
workspace.EditDocument(True, emailDoc) 
End Sub

"tmpResponse" is a copy of the form 
"Response" in the target database with this:

Sub Queryclose(Source As 
Notesuidocument, Continue As Variant)
 Set workspace = 
New NotesUIWorkspace
 Set sess = New NotesSession
 Set db = sess.CurrentDatabase
 Set uidoc = 
 Set doc = uidoc.Document 
 Dim parDoc As Notesdocument
 doc.Form = "Response"
 Set parDoc = db.
 Call doc.MakeResponse(parDoc) 
 Call doc.Save(True,False)
End Sub

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Brian Moore. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on LotusScript

  • Favorite iSeries cheat sheets

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