0

Apologies for my poor understanding of references/COM/dlls.


I have a VB.Net application without Option Strict. It uses the code below to send lotus emails.

Dim s As Object = CreateObject("Notes.Notessession")
Dim db As Object = s.GetDatabase("", "")
Call db.openmail()
doc = db.CreateDocument
doc.ReplaceItemValue("SendTo", "someEmail@someEmailSpot.com")
doc.ReplaceItemValue("Subject", "Some subject text")
doc.ReplaceItemValue("Body", "Some body text")
Call doc.Send(False)

When I recreate the code with Option Strict the

Dim db As Object = s.GetDataBase("", "")

line has a late binding error, under s.GetDataBase, which I don't know how to resolve. I can't find a reference to add to my project so that I can cast it to a Notes.Notessession.

I was instead able to use the following reference -- "Lotus Domino Objects" Interop.Domino.dll -- to write the code below.

Dim session As New Domino.NotesSession
session.Initialize()
Dim dir As Domino.NotesDbDirectory = session.GetDbDirectory("")
dir.OpenMailDatabase()
Dim db As Domino.NotesDatabase = dir.OpenMailDatabase
Dim doc As Domino.NotesDocument = db.CreateDocument
doc.ReplaceItemValue("SendTo", "someEmail@someEmailSpot.com")
doc.ReplaceItemValue("Subject", "Some subject text")
doc.ReplaceItemValue("Body", "Some body text")
doc.Send(False)

The problem is it seems Domino.NotesSession requires me to provide a password where Notes.NotesSession did not, either as a parameter in initialize or in a prompt that is created if no password is passed, like the code above.


My questions are:

  1. Is there a way for the Domino.NotesSession object to initialize without needing a password, like the Notes.NotesSession object does?

  2. What is being referenced at runtime to create the Notes.NotesSession object, and how can I add this reference at design time?

  3. Is there a view to view what type of object something has late bound to at runtime? Presumably in the first code block, s is being binded to a Notes.Notessession, but viewing it in watch or using TypeOf just return a generic "_ComObject".

Greg
  • 414
  • 4
  • 12

2 Answers2

3

Notes.NotesSession is the root of the OLE objects for the Notes client. Domino.NotesSession is the root of the COM objects for Notes/Domino data.

The OLE objects can avoid a password prompt only if the Notes client is already running. If it's not running, invoking the OLE object starts the client and prompts for a password. Most people avoid using the OLE objects unless they are actually going to use them to drive the Notes UI, which is done with the Notes.NotesUIWorkspace and various other NotesUI classes.

Since Domino.NotesSession is COM, it runs independently of the client, but it still uses the Notes APIs that were installed with the client. There is a checkbox in Notes' security settings (File - Security - User Security - Security Basics) labeled "Don't prompt for a password from other Notes-based programs". If you check that box, then you won't get a password prompt when you invoke the COM classes if the Notes client is already running. Essentially that puts you on equal footing with using the OLE classes. But note: Right next to that check box item's description, in parenthesis, it says "(reduces security)". A lot of people do choose to enable this setting, but you do need to be aware that it does potentially open a hole through which untrustworthy code might be able to access Notes database information using a the user's credentials.

Regarding why you do/don't see the references in the IDE, let's just say that it's always been inconsistent and leave it at that. I can't give you any rhyme or reason. That said, it's probably better not to see the Notes.NotesSession reference because it just confuses people if they see both. Most people should be using the COM classes.

Richard Schwartz
  • 14,463
  • 2
  • 23
  • 41
  • Extremely helpful ! Would you expand on adding/finding a reference to the OLE objects? I've been trying to locate it from the progID in the registry but am having trouble. – Greg Sep 03 '15 at 21:23
  • I'm afraid I don't have much more helpful to say about. I've seen the reference in the IDE in some confgurations, but I've seen it not there in others. I've never really investigated why it is or is not there, and don't have any good guesses other than "it's probably specific to what version(s) of Notes have been installed - due to bugs in the installer". And I don't have a VS install handy at the moment to do any checking into it for myself. – Richard Schwartz Sep 04 '15 at 03:43
1

Not sure this will answer your questions directly, hopefully it is helpful:

For Notes 6.5 on (at least) any client can send mail via code (no developer license needed.) If you don't have a client installed the code below will not work. And - if you do not have a current logged in session I don't think you can avoid providing a password.

Below is about the cleanest Send tool in my test code. One trick is that some properties, like addresses, prefer arrays and not a simple string.

Option Explicit On
Imports Domino ' ref to Interop.Domino.dll
Public Class frmLotousNotes
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim notesSession As Object, notesDatabase As Object, notesDocument As Object
        Dim aTo(0) As String
        Try
            'Instantiate Lotus Notes COM's objects.
            notesSession = CreateObject("Notes.NotesSession")
            notesDatabase = notesSession.GETDATABASE("", "")
            'Make sure Lotus Notes is open and available.
            If notesDatabase.IsOpen = False Then notesDatabase.OPENMAIL()
            'Create the document for the e-mail.
            notesDocument = notesDatabase.CreateDocument
            'Add data to the mainproperties of the e-mail's document.
            aTo(0) = txtTo.Text ' note array needed for some properties
            With notesDocument
                .Form = "Memo"
                .SendTo = aTo
                .Subject = txtSubject.Text & ": " & Now()
                .Body = txtMsg.Text
                .SaveMessageOnSend = True
            End With
            'Send the e-mail.
            With notesDocument
                .PostedDate = Now()
                .send(0, aTo)
            End With
            MsgBox("sent")
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            'Release objects from memory.
            notesDocument = Nothing
            notesDatabase = Nothing
            notesSession = Nothing
        End Try
    End Sub

End Class
rheitzman
  • 2,247
  • 3
  • 20
  • 36
  • Notes.NotesSession is able to send email without a password, despite a current logged in session of notes...at least on my machine. Just not Domino.NotesSession. – Greg Sep 03 '15 at 18:35
  • Your code is similar to mine, but it fails to pass with Option Strict on. – Greg Sep 03 '15 at 18:36
  • The array arguments is something I was unaware of, thank you for sharing. – Greg Sep 03 '15 at 18:37