Click here to Skip to main content
Click here to Skip to main content

Send Mails Through Lotus Notes Using Power Builder.

, 6 Jan 2006
Rate this:
Please Sign up or sign in to vote.
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.

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:

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

notesDocument = notesDatabase.CreateDocument

Setting the properties

Form

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

notesDocument.Form = "Memo"

Subject

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

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:

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")

Attachment

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] = 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:

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 Name Values Comments
DeliveryPriority L, N, H Values correspond to: low, normal or high-priority.
DeliveryReport N, B, C, T Values correspond to: none, only on failure, confirm delivery, trace entire path
Encrypt 1, 0 Use 1 to encrypt mailed documents.
ReturnReceipt 1, 0 Use 1 to send a receipt when the document is opened by the recipient.
Sign 1, 0 Use 1 to add an electronic signature to the fields. (Only applicable if a form also contains sign-enabled fields.)
SaveMessageOnSend True, False If true the document will be saved to the send item list.
PostedDate Today’s date time In 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.

Example

NotesDocument.Save(TRUE, FALSE ,TRUE)

Syntax

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

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:

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

About the Author

Dinesh1Kumar

United States United States
No Biography provided

Comments and Discussions

 
QuestionErorr in getDatabase using PB11 PinmemberArnfinn26-Oct-10 5:33 
GeneralBrilliant! Here's how to auto-fill recipients field PinmemberModern Talking15-Sep-10 6:41 
QuestionHow to get Lotus Version Number? PinmemberEricB - USA26-Mar-10 3:39 
QuestionPossible to make dialog visible before sending? Pinmemberalexjensendk6-Apr-09 10:13 
AnswerRe: Possible to make dialog visible before sending? Pinmembermamdu16-Dec-09 23:42 
GeneralSend a mail using a stationary PinmemberNabojyoti Sarkar24-Dec-08 4:32 
QuestionDelivery Options setting - Prevent Copying Pinmemberananth_siva30-Oct-08 23:40 
GeneralUnable to send mail through PinmemberPathan Ahamad9-Jun-08 3:18 
Generali have solve this problem Pinmemberlbtkhang31-Oct-07 15:20 
QuestionHow to send email with embbeded image Pinmemberlbtkhang31-Oct-07 0:39 
Questionhow to send html mail with image Pinmemberdevidyang31-Jan-07 22:55 
QuestionHow to extract Attachment details for MIME encoded Message ? PinmemberJagdish Vasani7-Dec-06 23:23 
GeneralSend mail using stationery PinmemberRafal Stajkowski1-Aug-06 23:07 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140718.1 | Last Updated 6 Jan 2006
Article Copyright 2006 by Dinesh1Kumar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid