How do I get an automatic email notification in Lotus Notes using VB?

Hi Folks,
I'm trying to generate an automatic email notification utility when a value in a program I use goes above a certain value. For a bit more info, I use a Process Information package called PI (from OSIsoft) for displaying trends and figures of various plant flows and temperatures. What I want to happen is when a flow/temp goes above a certain value, I get an email in Lotus Notes telling me that it has happened, almost like an error reporting function.

Attached is a piece of code which I was trying to use, but it keeps on giving me a runtime error 424. I've never heard of MAPI so I couldn't tell you anything about it! If you can help then please please do so. If you think this question would be better on the Lotus Notes section the just say so and I'll get it moved.



Private Sub Pt16187_DataUpdate()
' Script for tag: "DCU12_CPU_LOAD"
    If Pt16187.GetValue(0, 0) > 66 Then
        MAPISession1.Username = "Colin Welsh/Europe/MIC"
        MAPIMessages1.SessionID = MAPISession1.SessionID
        MAPIMessages1.RecipAddress = ""
        MAPIMessages1.RecipType = mapToList
        MAPIMessages1.MsgSubject = "DCU12_CPU_LOAD Update"
        MAPIMessages1.MsgNoteText = "DCU12 greater than 66%"
    End If

End Sub
Who is Participating?
TimCotteeConnect With a Mentor Commented:
Don't even think about MAPI for Notes, download the bas module from (downloads page) and plug it into your application. You can now send email including multiple attachments to multiple addressees in notes.
Try This: (works in asp also)
emailfrom =
emailto =
emailsubj =
emailbody =
emailfile = (in the form of drive:\filename.doc (i.e. c:\myfile.doc)
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
objNewMail.From = emailfrom
objNewMail.To = emailto
objNewMail.Subject = emailsubj
objNewMail.Body = emailbody & vbcrlf
objNewMail.BodyFormat = CdoBodyFormatText
objNewMail.MailFormat = CdoMailFormatText
objNewMail.Importance = CdoNormal
objNewMail.AttachFile emailfile
Set objNewMail = Nothing

Also, if using this code in VB dont need (Server.) portion of Server.CreateObject.


Therefore, your SMTP service must be installed and running on your NT or above box. :) Hope this helps.
ryderjam, you are not new to this site and should be aware of the guidelines on comments vs answers. Please re-read this at the bottom of this page or at the following link

If you continue to post answers, your account will be referred to customer services for possible penalty.

Caffreys, please reject this proposed answer at this point to allow other experts the opportunity to comment (it is currently in the "locked" section and will not get the attention it deserves as a result). You may of course accept any comment as an answer at any time.
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

caffreysAuthor Commented:
Thanks Tim for the info. I've rejected the answer as suggested as I want to try the various methods which have been suggested to see which one works the best. Sorry ryderjam but them's the breaks!
caffreysAuthor Commented:
Tim Cottee,

Right I've got the bas module from the website, but how do I get this to work in my VB code. All I have got is the code that I attached previously, nothing more, nothing less. There is only one object (if thats the right word) on the display. An idiots guide as to what I should add and remove in the code is probably my level!
You can probably tell that it is looking for the value to rise above 66 then it should generate the email in notes. The message to be displayed would be something like "value is above 66, do something now!" I'm not sending the message to anyone else, just myself, as I don't monitor everything at once.
Colin: all you need to do once you have added the module to your project is call the sub therein as follows:

SendNotesMail(Subject As String, Attachment As String, BodyText As String, SendTo As String, Optional CC As String = "", Optional BCC As String = "", Optional SaveIt As Boolean = False)

SendNotesMail "DCU12_CPU_LOAD Update","","DCU12 greater than 66%","Colin Welsh/Europe/MIC"

Obviously you need to have notes running on the machine that is running this application but that is pretty much it. You can put as much as you like in the body text, equally if you want to include attachments, just add a comma seperated list in this parameter. Equally sending to multiple recipients is simply a comma seperated list in the SendTo parameter. You can use the Notes name from your name & address book so it will be internally sent on your network rather than going out onto the internet and back.
caffreysAuthor Commented:

I get a run time error 429 - Active X component can't create object "Set Session = CreateObject ("Notes.NotesSession")

Any Thoughts?

Below is the whole code as is...
Public Sub SendNotesMail(Subject As String, Attachment As String, BodyText As String, SendTo As String, Optional CC As String = "", Optional BCC As String = "", Optional SaveIt As Boolean = False)
    'Set up the objects required for Automation into lotus notes
    Dim Maildb As Object 'The mail database
    Dim UserName As String 'The current users notes name
    Dim MailDbName As String 'THe current users notes mail database name
    Dim MailDoc As Object 'The mail document itself
    Dim AttachME As Object 'The attachment richtextfile object
    Dim Session As Object 'The notes session
    Dim EmbedObj As Object 'The embedded object (Attachment)
    'Start a session to notes
    Set Session = CreateObject("Notes.NotesSession")
    'Get the sessions username and then calculate the mail file name
    'You may or may not need this as for MailDBname with some systems you
    'can pass an empty string
    UserName = Session.UserName
    MailDbName = Left$(UserName, 1) & Right$(UserName, (Len(UserName) - InStr(1, UserName, " "))) & ".nsf"
    'Open the mail database in notes
    Set Maildb = Session.GETDATABASE("", MailDbName)
    If Maildb.ISOPEN = True Then
    'Already open for mail
    End If
    'Set up the new mail document
    Set MailDoc = Maildb.CREATEDOCUMENT
    With MailDoc
        .Form = "Memo"
        .SendTo = Split(SendTo, ",")
        .CopyTo = Split(CC, ",")
        .BlindCopyTo = Split(BCC, ",")
        .Subject = Subject
        .Body = BodyText
    'Set up the embedded object and attachment and attach it
        Dim aryAttachment() As String
        aryAttachment = Split(Attachment, "|")
        For intAttach = LBound(aryAttachment) To UBound(aryAttachment)
            Set AttachME = .CREATERICHTEXTITEM("Attachment" & CStr(intAttach))
            Set EmbedObj = AttachME.EMBEDOBJECT(1454, "", aryAttachment(intAttach), "Attachment" & CStr(intAttach))
            .CREATERICHTEXTITEM ("Attachment" & CStr(intAttach))
        Next intAttach
    'Send the document
        .PostedDate = Now() 'Gets the mail to appear in the sent items folder
        .SEND False
    End With
    'Clean Up
    Set Maildb = Nothing
    Set MailDoc = Nothing
    Set AttachME = Nothing
    Set Session = Nothing
    Set EmbedObj = Nothing
End Sub

Private Sub Pt16187_DataUpdate()
' Script for tag: "DCU12_CPU_LOAD"
    If Pt16187.GetValue(0, 0) > 66 Then
    SendNotesMail "DCU12_CPU_LOAD Update", "", "DCU12 greater than 66%", "Colin Welsh/EUROPE/MIC"
    End If
End Sub

Which version of Notes are you running, I have tested this with both 4.x and 5.x so it should be OK if notes is installed on the machine.
caffreysAuthor Commented:
It's version 5.0.6. of Lotus Notes, and yes it's running on the machine!

keep it simple

if a > b then  shell "MailSend -from -smtp -to -msg " & chr(34) & "A is bigger than B" & chr(34),vbhide

you could get gbmail in

hope this helps

sorry, radiks is down, in search for mailsend

since it is shareware i can email it to you. drop me an email to
Richie_SimonettiIT OperationsCommented:
if you are using Notes 5.x you could use COM instead of OLE
try sample at
sorry for the confusion  -- still not sure what I did, was just trying to help.
caffreysAuthor Commented:
Hi Folks,
Sorry for not looking at this sooner, but I've been on holiday.

Richie Simonetti - I can't get onto Is there any other site which has the sample on it.

caffreysAuthor Commented:
To ryderjam...
Can you give me an example of how your code would go into the VB sheet (has anyone guessed I know nothing about VB? - I hope so!). I'm not sure how to add it in when the function of the "greater than" comparison is true and needs to send the email.
Richie_SimonettiIT OperationsCommented:
Richie_SimonettiIT OperationsCommented:
Hi caffreys, any progress/need more help?
Just Ask.
caffreysAuthor Commented:

My company's internet policy won't let me get onto (crap company I work for!). If you could post the code on here somewhere then I'll take it, and see what I can do with it. It looks like I'm going to have to get my IT dept to have a look at the setup of my Lotus notes in order to allow it to do certain things with automatic email notification. I think that means I'll probably be able to give everyone an answer in about 2005!
Richie_SimonettiIT OperationsCommented:
Don't worry!, i think Tim or other guy/girl could help, even me!
Let's do the work... don't desperate.
Richie_SimonettiIT OperationsCommented:
Code from Tim would works, if not try:
(just for testing purpose, edit as you wish)
' set a reference to Lotus Domino objects (domobj.tlb)

Private Sub Form_Load()
' Creates new Notes session object and prompt user to
' enter servername, password and database mail.
' Prompt for password can be override if you pass password value
' as parameter of initialize method.
' This could be stored on registry/ini file to ask the
' user only the first time.
' I used inputbox for easy, you could add a form to get all
' values.
Set COMSess = New Domino.NotesSession

COMSess.Initialize InputBox$("Please enter Database password.", "Enter Password")
Set COMDB = COMSess.GetDatabase(InputBox$("Please enter Domino server name here.", "Server name", "FRE-AR-BA-H01"), _
                                    InputBox$("Please enter Domino database name here.", "Enter database name", "\mail\7\ARBA0137.nsf"), _
    If Not .IsOpen Then
        MsgBox "Unable to open Notes session.", vbCritical, "Init Error"
        Set COMDB = Nothing
        Set COMSess = Nothing
        Exit Sub
    End If
End With
End Sub

Private Sub cmdSend_Click()
Dim Doc As NotesDocument
Dim NItem As NotesItem

'Creates new document/message
Set Doc = COMDB.CreateDocument
    With Doc
        ' Creates Rich body item and adds all headers
        Set NItem = Doc.CreateRichTextItem("BODY")
        .AppendItemValue "Form", "memo"
        .AppendItemValue "SendTo", Text1(0).Text
        .AppendItemValue "CopyTo", Text1(1).Text
        .AppendItemValue "Subject", Text1(2).Text
        .AppendItemValue "BODY", Text1(3).Text
        ' Check is there is some files to attach to message
        ' if so, attaches them.
        If lstFiles.ListIndex <> -1 Then
            Dim obj As Object
            Dim i As Integer, UpperLstCount As Integer
            UpperLstCount = lstFiles.ListCount
            For i = 0 To UpperLstCount - 1
                lstFiles.Selected(i) = True
                Set obj = NItem.EmbedObject(EMBED_ATTACHMENT, "", lstFiles.Text)
            Next i
        End If
        .Send False
    End With

End Sub
Richie_SimonettiIT OperationsCommented:
Well, if above code doesn't works (i use it in a daily basis without problems) and
keeping in mind that i don't know IF Notes IS an SMTP server (or has such capability), you could use this component:
caffreysAuthor Commented:
Well Folks,
Todays prize winner is Tim Cottee. The reason for this is that we found a slight problem.... it worked on every other machine we tried it on but not mine! There is something in my initial installation of the PC, as a whole, which doesn't allow the VB code to run properly. I got our IT manager involved and he came up with the exact same code as Tim, but filled in the info for the server and email address. He then ran it on his machine which was fine, ran it on a machine in the office next to me and that was OK too. He then checked my machine and found that it had some errors in its setup.
Thanks to all who provided help, it was much appreciated.

All Courses

From novice to tech pro — start learning today.