Click here to Skip to main content
15,311,151 members
Articles / Programming Languages / VBScript
Posted 6 Jan 2006


19 bookmarked

Send Mails Through Lotus Notes Using Power Builder.

Rate me:
Please Sign up or sign in to vote.
4.56/5 (6 votes)
6 Jan 20065 min read
This article tries to give a basic idea on how to send mails through Lotus Notes using Power Builder.


This article tries to give a basic idea on how to send mails through Lotus Notes using Power Builder. This method uses the OLE object technique. Here, we use Lotus Notes' inbuilt classes to perform the required functions. We create objects of these classes as OLE objects. To know more about the Lotus Notes classes, please explore the following link.


  1. This code does not include proper error handing.
  2. This code was tested in Power Builder 10.0 (Build 4510) and Lotus Notes 6.5.
  3. Before running the code, please ensure that Lotus Notes is opened using the user machine procedure.

The following procedure uses the OLE object technique to send mails through Lotus Notes. The following OLE objects must be declared:

  1. Notes session object ("notesSession")
  2. Notes database object ("notesDatabase")
  3. Notes document object ("notesDocument")
  4. RTF object ("notesRichTextItem") – this object is used to create attachments in Notes.

Step 1: Creating the connection to Lotus Notes

First, a connection to Lotus Notes has to be made using the "ConnectTONewObject" command.

notesSession = Create oleobject

Step 2: Connecting to the database

After a session has been created with Notes, a database has to be opened. This is done by the "GetDatabase" command.

The GetDatabase method creates a NotesDatabase object that represents the database located at the server. The first parameter is the server name and the second parameter is the username. Usually, we have to specify the server and the user name. Giving these as blank will connect to the default server.


For the default server connection:

notesDatabase = notesSession.GetDatabase("","")

For other databases:

notesDatabase = notesSession.GetDatabase("<SERVER >"," <USERNAME >")

After connecting to the database, the mailbox has to be opened. This is done using the "OpenMail" command. The OpenMail method finds the current user's mail server and the database in the notes.ini file and opens it. It is a good practice to first check whether the current user’s database is open and then open it if it's not.

IF NOT notesDatabase.IsOpen THEN

Step 3: Creating the document

After the database has been opened, a new Notes document has to be created (in Notes, a new mail is represented as a document). This is done using the "CreateDocument" command.

The CreateDocument method creates a document in the database and returns a NotesDocument object that represents the new document.

notesDocument = notesDatabase.CreateDocument

Setting the properties


Set the Form to "Memo" so that its recipient can read it as a mail memo:

notesDocument.Form = "Memo"


Use the subject property to set the subject of the mail:

notesDocument.Subject = "Hello"


The body of the mail can be treated as a rich text item. Creating a new rich text item in a document is done using the "CreateRichTextItem" command.

The CreateRichTextItem method creates a new rich text item in a document, using a name you specify, and returns the corresponding NotesRichTextItem object:

notesRichTextItem = notesDocument.CreateRichTextItem("Body")

After creating the RTF object, the text can be appended to the body of the mail using the "AppendText" command.

NotesRichTextItem.AppendText("Here comes the body of the mail")


Attachments can be added to the RTF object using the "EmbedObject" command.

NotesRichTextItem.EmbedObject*(1454, "", "<Attachment Path>", "")

This command will add only one attachment to the mail body. To add more attachments, we need to reuse the same command. The third parameter would be blank and the first parameter would be set to 1454.

For example:

NotesRichTextItem.EmbedObject(1454, "", "C:\Attachment1.doc", "")
NotesRichTextItem.EmbedObject(1454, "", "C:\Attachment2.doc", "")

Recipients setup

The recipient’s mail IDs are in the form of a string. In the case of multiple recipients, an array of strings should be used.

See the example below to set-up multiple recipients:

String Recipient_arr[]

Recipient_arr[1] =
Recipient_arr[2] =

In order to set this list as the "To" list, use the "SendTo" property:

NotesDocument. SendTo = Recipient_arr

In order to set this list as the "CC" list, use the "CopyTo" property:

NotesDocument.CopyTo = Recipient_arr

In order to set this list as the "BCC" list, use the "BlindCopyTo" property:

NotesDocument.BlindCopyTo= Recipient_arr

Other properties of the document object

Reserved Field NameValuesComments
DeliveryPriorityL, N, HValues correspond to: low, normal or high-priority.
DeliveryReportN, B, C, TValues correspond to: none, only on failure, confirm delivery, trace entire path
Encrypt1, 0Use 1 to encrypt mailed documents.
ReturnReceipt1, 0Use 1 to send a receipt when the document is opened by the recipient.
Sign1, 0Use 1 to add an electronic signature to the fields. (Only applicable if a form also contains sign-enabled fields.)
SaveMessageOnSendTrue, FalseIf true the document will be saved to the send item list.
PostedDateToday’s date timeIn PB, this can be retrieved using the "NOW" function.

Note: Here, even the numeric values should be set as characters, e.g.:

NotesDocument.ReturnReceipt = ‘1’

Saving the document

The Save method is used to save any changes made to the document.


NotesDocument.Save(TRUE, FALSE ,TRUE)


notesDocument.Save( force, createResponse [, markRead ] )


  • force

    Boolean. If True, the document is saved even if someone else edits and saves the document while the script is running. The last version of the document that was saved wins; the earlier version is discarded. If False, and someone else edits the document while the script is running, the createResponse argument determines what happens to the document.

  • createResponse

    Boolean. If True, the current document becomes a response to the original document (this is what the replicator does when there's a replication conflict). If False, the save is canceled. If the force parameter is True, the createResponse parameter has no effect.

  • markRead

    Boolean. If True, the document is marked as read. If False (default), the document is not marked as read.

Step 4: Sending the document

When the document is prepared, it is sent using the "Send" command.



Now, the process of sending the mail is completed.

Step 5: Cleanup

After sending the mails, the user needs to free the memory and close all the connections. This involves disconnecting the session object and destroying the OLE objects:


DESTROY NotesSession
DESTROY NotesDatabase
DESTROY NotesDocument
DESTROY NotesRichTextItem


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

United States United States
No Biography provided

Comments and Discussions

QuestionErorr in getDatabase using PB11 Pin
Arnfinn26-Oct-10 5:33
MemberArnfinn26-Oct-10 5:33 
GeneralBrilliant! Here's how to auto-fill recipients field Pin
Modern Talking15-Sep-10 6:41
MemberModern Talking15-Sep-10 6:41 
QuestionHow to get Lotus Version Number? Pin
EricB - USA26-Mar-10 3:39
MemberEricB - USA26-Mar-10 3:39 
QuestionPossible to make dialog visible before sending? Pin
alexjensendk6-Apr-09 10:13
Memberalexjensendk6-Apr-09 10:13 
AnswerRe: Possible to make dialog visible before sending? Pin
mamdu16-Dec-09 23:42
Membermamdu16-Dec-09 23:42 
GeneralSend a mail using a stationary Pin
Nabojyoti Sarkar24-Dec-08 4:32
MemberNabojyoti Sarkar24-Dec-08 4:32 
QuestionDelivery Options setting - Prevent Copying Pin
ananth_siva30-Oct-08 23:40
Memberananth_siva30-Oct-08 23:40 
GeneralUnable to send mail through Pin
Pathan Ahamad9-Jun-08 3:18
MemberPathan Ahamad9-Jun-08 3:18 
Generali have solve this problem Pin
lbtkhang31-Oct-07 15:20
Memberlbtkhang31-Oct-07 15:20 
QuestionHow to send email with embbeded image Pin
lbtkhang31-Oct-07 0:39
Memberlbtkhang31-Oct-07 0:39 
Questionhow to send html mail with image Pin
devidyang31-Jan-07 22:55
Memberdevidyang31-Jan-07 22:55 
QuestionHow to extract Attachment details for MIME encoded Message ? Pin
Jagdish Vasani7-Dec-06 23:23
MemberJagdish Vasani7-Dec-06 23:23 
GeneralSend mail using stationery Pin
Rafal Stajkowski1-Aug-06 23:07
MemberRafal Stajkowski1-Aug-06 23:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.