Solved

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

Posted on 2002-04-18
23
447 Views
Last Modified: 2012-06-21
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.

Thanks

Caffreys

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

End Sub
0
Comment
Question by:caffreys
  • 8
  • 6
  • 4
  • +2
23 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 total points
Comment Utility
Don't even think about MAPI for Notes, download the bas module from http://www.geocities.com/TimCottee (downloads page) and plug it into your application. You can now send email including multiple attachments to multiple addressees in notes.
0
 

Expert Comment

by:ryderjam
Comment Utility
Try This: (works in asp also)
----------------------------------------------------------------------------------------------------------------------
POPULATE THE FOLLOWING
----------------------------------------------------------------------------------------------------------------------
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
objNewMail.Send
Set objNewMail = Nothing


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

THIS CODE USES THE CDONTS FEATURE OF IIS Server.

Therefore, your SMTP service must be installed and running on your NT or above box. :) Hope this helps.
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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 http://www.experts-exchange.com/visualbasic/Q.20290887.html#tip

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

Author Comment

by:caffreys
Comment Utility
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!
0
 

Author Comment

by:caffreys
Comment Utility
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.
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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.
0
 

Author Comment

by:caffreys
Comment Utility
Tim,

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
    Else
    Maildb.OPENMAIL
    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
        .SAVEMESSAGEONSEND = SaveIt
    '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

 
0
 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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.
0
 

Author Comment

by:caffreys
Comment Utility
It's version 5.0.6. of Lotus Notes, and yes it's running on the machine!
0
 
LVL 1

Expert Comment

by:olx
Comment Utility

keep it simple

if a > b then  shell "MailSend -from me@there.com -smtp mail.there.com -to whoever@whatever.com -msg " & chr(34) & "A is bigger than B" & chr(34),vbhide

you could get gbmail in

http://www.radiks.net/jimbo/share.html

hope this helps

0
 
LVL 1

Expert Comment

by:olx
Comment Utility
sorry, radiks is down, in http://www.softpile.com search for mailsend

0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 1

Expert Comment

by:olx
Comment Utility
since it is shareware i can email it to you. drop me an email to

drplomo@mad.scientist.com
or
hugoalejandrotorres@yahoo.com
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
if you are using Notes 5.x you could use COM instead of OLE
try sample at www.angelfire.com.realm/vb-shatrd/index.html
Cheers
0
 

Expert Comment

by:ryderjam
Comment Utility
sorry for the confusion  -- still not sure what I did, was just trying to help.
0
 

Author Comment

by:caffreys
Comment Utility
Hi Folks,
Sorry for not looking at this sooner, but I've been on holiday.

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

Thanks
0
 

Author Comment

by:caffreys
Comment Utility
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.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Hi caffreys, any progress/need more help?
Just Ask.
Cheers
0
 

Author Comment

by:caffreys
Comment Utility
Richie,

My company's internet policy won't let me get onto angelfire.com (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!
Cheers
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Don't worry!, i think Tim or other guy/girl could help, even me!
Let's do the work... don't desperate.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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"), _
                                    False)
With COMDB
    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
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
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:
http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 

Author Comment

by:caffreys
Comment Utility
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.

Caffreys
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 48
String manipulation in Visual Basic 7 43
vb6 connector to mongodb 2 23
Spell Check in VB6 13 40
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now