IBM Support

How to send Lotus Notes mail messages with Microsoft Visual Basic



Customers with Microsoft® Visual Basic (VB) or VB.NET applications might want to integrate Lotus Notes® e-mail functionality. Is there an example of how to create a Notes® e-mail from Visual Basic?


The following Microsoft Visual Basic 6 (VB6) code sends a Notes e-mail message. It includes examples of code to include an attachment and to save the sent message, which are both optional and can be removed if desired.

IMPORTANT NOTE: This is sample code, provided only to illustrate one way to approach this issue. IBM Support will not be able to customize this script for a customer's own configuration. While this may work for some customers it is offered as a suggestion only, and is not something that IBM Lotus software supports further.

    Dim Maildb As Object
    Dim MailDoc As Object
    Dim Body As Object
    Dim Session As Object
    'Start a session to notes
    Set Session = CreateObject("Lotus.NotesSession")
    'This line prompts for password of current ID noted in Notes.INI
    Call Session.Initialize
    'or use below to supply password of the current ID
    'Call Session.Initialize("<password>")
    'Open the mail database in notes
    Set Maildb = Session.GETDATABASE("", "c:\notes\data\mail\mymail.nsf")
    If Not Maildb.IsOpen = True Then
    Call Maildb.Open
    End If
    'Create the mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    Call MailDoc.ReplaceItemValue("Form", "Memo")
    'Set the recipient
    Call MailDoc.ReplaceItemValue("SendTo", "John Doe")
    'Set subject
    Call MailDoc.ReplaceItemValue("Subject", "Subject Text")
    'Create and set the Body content
    Set Body = MailDoc.CREATERICHTEXTITEM("Body")
    Call Body.APPENDTEXT("Body text here")
    'Example to create an attachment (optional)
    Call Body.ADDNEWLINE(2)
    Call Body.EMBEDOBJECT(1454, "", "C:\filename", "Attachment")
    'Example to save the message (optional)
    'Example to set high priority (optional)
    MailDoc.DeliveryPriority = "H"
    'Example to set return receipt (optional)
    MailDoc.DeliveryReport = "B"
    'Send the document
    'Gets the mail to appear in the Sent items folder
    Call MailDoc.ReplaceItemValue("PostedDate", Now())
    Call MailDoc.SEND(False)
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set Body = Nothing
    Set Session = Nothing

Note: The Visual Basic programmer needs to set the Reference to use Lotus Domino® objects prior to implementing this function. To enable the Lotus Notes classes to appear in the Visual Basic browser, you must execute the following within VB: Select Tools, References and select the checkbox for 'Lotus Notes Automation Classes'.
Cross reference information
Product Component Platform Version Edition
IBM Notes Lotus Notes Windows 8.0, 7.0, 6.5, 6.0, 5.0 All Editions

Document information

More support for: IBM Domino Designer

Component: --, Lotus Notes, ">More...

Software version: 5.0, 6.0, 6.5, 7.0, 8.0, 8.5, 9.0

Operating system(s): Windows

Software edition: All Editions

Reference #: 1178583

Modified date: 29 June 2018

Translate this page: