Link to home
Start Free TrialLog in
Avatar of leekf
leekf

asked on

Lotus notes in Visual basic: GetDatabase

The following is visual basic code for Lotus Notes.

My users have two emails account in their Lotus Notes. I want my program to launch the account that can send external email. How can I specify that the particular Notes database is used?

In the notes property of the database, I found:

Server:
NS1BK11/SRV/DBG

Filename:
mail/kflee.nsf

But my code doesn't work, Lotus Notes cannot send the email, probably because the value after
Set OLEDB = OLESess.GetDatabase
is incorrect.

Any Idea?

    Dim OLESess As Object
    Dim OLEDB As Object
    Set OLESess = CreateObject("Notes.Notessession")
    Set OLEDB = OLESess.GetDatabase("NS1BK11/SRV/DBG", "mail\kflee.nsf") <========
    With OLEDB
        .OPENMAIL
        If Not .IsOpen Then
            MsgBox ("Unable to open Notes session. Sorry, you have to send mannually.")
            Exit Function
        End If
    End With

    On Error GoTo NotesError
    Const EMBED_ATTACHMENT = 1454
    ' Creates a new document/message.
    Dim Doc As Object
    Dim NItem As Object
    Set Doc = OLEDB.CreateDocument
    With Doc
        ' creates body of message and populates headers
        Set NItem = Doc.CreateRichTextItem("BODY")
        .Form = "Memo"
        .Subject = MySubject
        .SendTo = MySendTo
        .CopyTo = MyCopyTo
        .Body = MyBody
        .postdate = Date
        .SaveMessageOnSend = True
        .PostedDate = Now
        Call NItem.EmbedObject(EMBED_ATTACHMENT, "", MyAttach)
        .Send False
    End With

    On Error Resume Next
    Set OLEDB = Nothing
    Set OLESess = Nothing
    Exit Function
Avatar of flavo
flavo
Flag of Australia image

I never used lotus notes before (i use Groupwise)

but i have seen an example using

Set OLEDB = OLESess.GETDATABASE("", MailDbName)

where MailDbName = THe current users notes mail database name

and this

   Set objDB = objSession.GETDATABASE("", "names.nsf")

So im thinking you many not need to pass the server name "NS1BK11/SRV/DBG"  ???  no-one else seems to.

Hope this helps...

Dave
Avatar of GrahamSkan
I always recommend using early binding by setting a reference to Lotus Domino Objects

There are some examples using early and late binding to read notes mail here:

https://www.experts-exchange.com/questions/20445195/Lotus-Notes-Automation-Classes.html?query=Session.Initialize&clearTAFilter=true
Just remove the "        .OPENMAIL" line.
When you use GetDatabase it already opens the database and .OpenMail will only cause problems.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial