Click here to Skip to main content
15,867,141 members
Articles / Programming Languages / VBScript
Article

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 103.9K   2.1K   19   13
This article tries to give a basic idea on how to send mails through Lotus Notes using Power Builder.

Introduction

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.

Note

  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.

VBScript
notesSession = Create oleobject
notesSession.ConnectTONewObject("Notes.Notessession")

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.

Syntax

For the default server connection:

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

For other databases:

VBScript
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.

VBScript
IF NOT notesDatabase.IsOpen THEN
       notesDatabase.OpenMail()
END IF

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.

VBScript
notesDocument = notesDatabase.CreateDocument

Setting the properties

Form

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

VBScript
notesDocument.Form = "Memo"

Subject

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

VBScript
notesDocument.Subject = "Hello"

Body

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:

VBScript
notesRichTextItem = notesDocument.CreateRichTextItem("Body")

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

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

Attachment

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

VBScript
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:

VBScript
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:

VBScript
String Recipient_arr[]

Recipient_arr[1] = recp1.one@tcs.com
Recipient_arr[2] = recp2.two@tcs.com

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

VBScript
NotesDocument. SendTo = Recipient_arr

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

VBScript
NotesDocument.CopyTo = Recipient_arr

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

VBScript
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.:

VBScript
NotesDocument.ReturnReceipt = ‘1’

Saving the document

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

Example

VBScript
NotesDocument.Save(TRUE, FALSE ,TRUE)

Syntax

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

Parameters

  • 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.

Syntax

VBScript
NotesDocument.Send(FALSE)

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:

VBScript
notesSession.close()
notesSession.DisconnectObject()

DESTROY NotesSession
DESTROY NotesDatabase
DESTROY NotesDocument
DESTROY NotesRichTextItem

License

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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionErorr in getDatabase using PB11 Pin
Arnfinn26-Oct-10 5:33
Arnfinn26-Oct-10 5:33 
GeneralBrilliant! Here's how to auto-fill recipients field Pin
Modern Talking15-Sep-10 6:41
Modern Talking15-Sep-10 6:41 
I just tried that with some minor modifications and it worked! Thanks very much for this nice "Lotus-PB 101" demo.

I was asked to build in an auto-emailing feature into our PB app that would automatically notify them via Notes in the event of their DB password nearing expiration (and also send e-mail to DB Admin).

This is how I obtain current Notes user name:

ls_user = notesSession.CommonUsername


From there, it can be parsed and concatenated with "@XXX.com" to form an e-mail address string.
QuestionHow to get Lotus Version Number? Pin
EricB - USA26-Mar-10 3:39
EricB - USA26-Mar-10 3:39 
QuestionPossible to make dialog visible before sending? Pin
alexjensendk6-Apr-09 10:13
alexjensendk6-Apr-09 10:13 
AnswerRe: Possible to make dialog visible before sending? Pin
mamdu16-Dec-09 23:42
mamdu16-Dec-09 23:42 
GeneralSend a mail using a stationary Pin
Nabojyoti Sarkar24-Dec-08 4:32
Nabojyoti Sarkar24-Dec-08 4:32 
QuestionDelivery Options setting - Prevent Copying Pin
ananth_siva30-Oct-08 23:40
ananth_siva30-Oct-08 23:40 
GeneralUnable to send mail through Pin
Pathan Ahamad9-Jun-08 3:18
Pathan Ahamad9-Jun-08 3:18 
Generali have solve this problem Pin
lbtkhang31-Oct-07 15:20
lbtkhang31-Oct-07 15:20 
QuestionHow to send email with embbeded image Pin
lbtkhang31-Oct-07 0:39
lbtkhang31-Oct-07 0:39 
Questionhow to send html mail with image Pin
devidyang31-Jan-07 22:55
devidyang31-Jan-07 22:55 
QuestionHow to extract Attachment details for MIME encoded Message ? Pin
Jagdish Vasani7-Dec-06 23:23
Jagdish Vasani7-Dec-06 23:23 
GeneralSend mail using stationery Pin
Rafal Stajkowski1-Aug-06 23:07
Rafal 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.