Send email notification with LotusScript

Lotus Notes and Domino is not only  about email, it’s more than that. One of it’s feature it workflow, where people can create workflow application faster an d easier than any other application out there.

One of the important thing in workflow is email notification, to let users know that they have one job to do, or just simply notification.

Example,  if a staff create a leave request and when he or she submit the request, his or her manager will get an email notification about the request.

I have this one of my favorite sub program to create an email notification, well I named it “CreateEmailNotification” 🙂 .

If you like, you can use it for free. Just copy the sub program in one or new Script Library.

This is the sub program.

=====Start of Sub Program
Sub CreateMailNotification(doc As notesdocument, strSendTo As Variant, strSubject As String, strCopyTo As Variant)

Dim session As notessession
Dim db As notesdatabase
Dim docMail As notesdocument
Dim rtitem As Variant

Set db = doc.parentdatabase
Set session = db.Parent
Set docMail=db.createdocument
Set rtitem=docMail.CreateRichTextItem(“Body”)

If strSendTo(0)=”” Then Exit Sub

‘=====set mail
docMail.Form = “Memo”
docMail.From = session.UserName
docMail.Principle = session.UserName
docMail.SendTo = strSendTo

If Isarray(strCopyTo) Then
If strCopyTo(0)<>”” Then
docMail.CopyTo = strCopyTo
End If
If strCopyTo<>”” Then
docMail.CopyTo = strCopyTo
End If
End If

docMail.Recipients = strSendTo
docMail.Subject = strSubject
docMail.PostedDate = Now

‘=====set body field
Call rtitem.AppendText(“Please click this doclink to see more details about the status ” + ” “)
Call rtitem.AppendDocLink( doc, “click to open document”)
Call rtitem.AddNewLine( 2 )

‘=====send mail
Call docMail.send(False)
End Sub
=====End of Sub Program

Feel free to do some modification if necessary.

You can call it from any lotusscript with simple line like this.

call Call CreateMailNotification (doc, doc.nmSendTo, strSubject,doc.nmCopyTo)

Don’t forget to put use “Script Libary Name” first.

5 thoughts on “Send email notification with LotusScript

  1. kberg says:

    We use the Ionet Workflow Manager for developing our Workflow applications. With this engine workflows can be created very easy, no programmeing experience needed.

  2. eye zack says:

    hi, im still new. how to create a lotus script that will send an email to multiple user based on view selection from “view”?? thanks..

  3. bfebrian says:

    @eye zack: you need to extract the list of users into a variant, than you can put them into the script above (variable strSendTo).
    you can use notesdocumetcollection class to collect the documets from the view.

  4. eye zack says:

    Here is sample of my agent. this agent sent notification only to me. my program is like this : every document have their own email which i set as (appid). is there any other simple code that you know for share??

    Sub Domain (s As NotesSession, db As NotesDatabase)

    On Error Goto errhandler
    Print “Domain – Start – ” & Now()

    Dim view As NotesView
    Dim doc As NotesDocument
    Dim mailDoc As NotesDocument
    Dim rtitem As NotesRichTextItem
    Dim richStyle As NotesRichTextStyle

    REM – for multiple user name
    Dim i As Integer
    Dim j As Integer
    Dim UserList()
    Dim FinalList As Variant
    Dim item1 As NotesItem

    Set view = db.GetView(“smv-DomainLessFive”)
    Set doc = view.GetFirstDocument()

    If Not doc Is Nothing Then

    REM – for multiple username
    i = 0
    j = 0
    Set item1 = doc.GetFirstItem(“appid”)

    Forall a In item1.Values
    If a “” Then
    i = i + 1
    End If
    End Forall
    i = i – 1
    Redim UserList(i)

    Forall b In item1.Values
    If b “” Then
    If Not j > i Then
    UserList(j) = b
    j = j + 1
    End If
    End If
    End Forall
    FinalList = Arrayunique(UserList, 0)

    Set mailDoc = New NotesDocument(db)
    Set rtitem = New NotesRichTextItem(mailDoc, “Body”)
    Set richStyle = s.CreateRichTextStyle

    mailDoc.Form = “Memo”
    mailDoc.From = “Domino Server”
    mailDoc.Subject = “Reminder – Domain Expiry Date Less Than 5 Day(s)!”

    richStyle.Bold = True
    richStyle.NotesColor = COLOR_RED
    richStyle.FontSize = 14
    Call rtitem.AppendStyle(richStyle)

    Call rtitem.AppendText(“Reminder – Domain Expiry Date Less Than 5 Day(s)!”)
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“Domain(s) Listed Below Requires Your Immediate Attention!”)

    Do While Not doc Is Nothing

    richStyle.Bold = False
    richStyle.NotesColor = COLOR_BLACK
    richStyle.FontSize = 10
    Call rtitem.AppendStyle(richStyle)

    Call rtitem.AddNewLine(2)
    Call rtitem.AppendText(“Company Name : ” &
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“Domain Name : ” & doc.DomainName(0))
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“Domain License : ” & doc.DomainLicenseNumber(0))
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“Expiry Date : ” & Cstr(doc.Domain_Expired_Date(0)))
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“Agent Name : ” & Cstr(doc.DA_Name(0)))

    richStyle.Bold = True
    richStyle.NotesColor = COLOR_RED
    richStyle.FontSize = 10
    Call rtitem.AppendStyle(richStyle)

    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“Total Day(s) Left : ” & Cstr(Cdbl(doc.Domain_Expired_Date(0)) – Cdbl(Date())))

    Set doc = view.GetNextDocument(doc)

    richStyle.Bold = False
    richStyle.NotesColor = COLOR_BLACK
    richStyle.FontSize = 8
    Call rtitem.AppendStyle(richStyle)

    Call rtitem.AddNewLine(2)
    Call rtitem.AppendText(“Kindly act on it accordingly. Your immediate attention in this matter is much appreciated”)
    Call rtitem.AddNewLine(1)
    Call rtitem.AppendText(“** Note: This is a computer generated mail, therefore there’ll be no sender name attached **”)
    Call mailDoc.Send(False, FinalList) ‘for multiple username

    End If

    Print “Domain – Start – ” & Now()
    Exit Sub


    Print “Sub/Function : ” & Lsi_info(2)
    Print “Error Line : ” & Erl
    Print “Error Message : ” & Error

    Resume finish

    End Sub

  5. eye zack says:

    each form have field that hold email address.. ok.. how to notify email using that field? using agent that on schedule. so that mean each document will be notify using that email? please help me.

Leave a Reply