Link to home
Start Free TrialLog in
Avatar of Hoboly
Hoboly

asked on

running out of resource after calling lotus notes api many times~~

I wrote a robot program to call lotus notes API to send emails by different email a/c
the program works very well for the first few hours
but after around 4 hours, it is unable to call lotus notes API to call email (error in the following open function)

I suspect that I need to close / dispose the lotus notes API object.
but I have no ideas what need to close / dispose.

Could anyone help me, please?
Thanks!
Public Sub sendEmail()
 
 
        Dim recep As String() = ssMailTo
        Dim ccRecipient As String() = New String() {}
        Dim subj As String = sSubjectSend
        Dim mailbody As String = "This is robot message." '"hi" + ControlChars.NewLine + "bye"
 
        Dim savemsg As Boolean
 
        open()
 
 
        Dim domNotesDocumentMemo As NotesDocument
        Dim DomNotesItem As NotesItem
        Dim sUser As String
        Dim objNotesRichTextItem As NotesRichTextItem
 
 
 
        ' Create a new memo document.
        domNotesDocumentMemo = domDB.CreateDocument
 
 
        Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")
        Dim body As NotesMIMEEntity
        'body = domNotesDocumentMemo.CreateMIMEEntity
        'body.CreateHeader("Subject").SetHeaderVal(subj)
        'body.CreateHeader("To").SetHeaderVal(String.Join(";", recep))
        'body.SetContentFromText _
        ' (Nothing, "text/plain;charset=UTF-8", MIME_ENCODING.ENC_NONE)
        body = domNotesDocumentMemo.CreateMIMEEntity
        Dim header As Domino.NotesMIMEHeader
        header = body.CreateHeader("Subject")
        Call header.SetHeaderVal(subj)
        header = body.CreateHeader("To")
        Call header.SetHeaderVal(String.Join(";", recep))
        header = body.CreateHeader("From")
        Call header.SetHeaderVal(domS.UserName)
        header = body.CreateHeader("Replyto")
        Call header.SetHeaderVal(domS.UserName)
 
 
        Call domNotesDocumentMemo.ReplaceItemValue("$INETReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("ReplyTo", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("Principal", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("$InetPrinicipal", domS.UserName)
        Call domNotesDocumentMemo.ReplaceItemValue("$AssistMail", Nothing)
        Call domNotesDocumentMemo.RemoveItem("$AssistMail")
        Call domNotesDocumentMemo.ReplaceItemValue("$TITLE", Nothing)
        Call domNotesDocumentMemo.ReplaceItemValue("InetSendTo", recep)
        'Call domNotesDocumentMemo.ReplaceItemValue("Form", "Memo")
        Call domNotesDocumentMemo.ReplaceItemValue("useApplet", "True")
        Call domNotesDocumentMemo.ReplaceItemValue("DefaultMailSaveOptions", "1")
        Call domNotesDocumentMemo.ReplaceItemValue("$StorageTo", "1")
        Call domNotesDocumentMemo.ReplaceItemValue("$Mailer", "Lotus Notes Release 6.5.4 March 27, 2005")
 
        'Call domNotesDocumentMemo.AppendItemValue("SendTo", "")
        ''Now get a handle on the item
        'DomNotesItem = domNotesDocumentMemo.GetFirstItem("SendTo")
        ''Now pass your array
        'For Each r As String In recep
        '    If r <> "" Then
        '        Call DomNotesItem.AppendToTextList(r)
        '    End If
        'Next
 
        Call domNotesDocumentMemo.ReplaceItemValue("SendTo", recep)
        Call domNotesDocumentMemo.ReplaceItemValue("CopyTo", ccRecipient)
 
        Call domNotesDocumentMemo.AppendItemValue("Subject", subj)
        'objNotesRichTextItem = domNotesDocumentMemo.CreateRichTextItem("Body")
 
        'Dim body As NotesMIMEEntity
        ''body = domNotesDocumentMemo.CreateMIMEEntity
        ''body.CreateHeader("Subject").SetHeaderVal(subj)
        ''body.CreateHeader("To").SetHeaderVal(String.Join(";", recep))
        ''body.SetContentFromText _
        '' (Nothing, "text/plain;charset=UTF-8", MIME_ENCODING.ENC_NONE)
        'body = domNotesDocumentMemo.CreateMIMEEntity
        'Dim header As Domino.NotesMIMEHeader
        'header = body.CreateHeader("Subject")
        'Call header.SetHeaderVal("MIME message")
        'header = body.CreateHeader("To")
        'Call header.SetHeaderVal("Roberta Person")
        'Dim stream As Domino.NotesStream
        'Call stream.WriteText("Text of message.")
        'Call body.SetContentFromText _
        '(stream, "text/plain;charset=UTF-8", MIME_ENCODING.ENC_NONE)
 
 
        'Call objNotesRichTextItem.AppendText(mailbody)
 
        If Trim(LCase(savemsg)) = "yes" Then
            domNotesDocumentMemo.SaveMessageOnSend = True
        Else
            domNotesDocumentMemo.SaveMessageOnSend = False
        End If
        domNotesDocumentMemo.Send(False)
        domNotesDocumentMemo = Nothing
 
        close()
 
    End Sub
 
 
 
 
 
 
 
    Public Function open() As Boolean
 
        IO.File.Copy(IO.Path.Combine(IO.Directory.GetCurrentDirectory, sIDfilePath), IO.Path.Combine(notesDataPath, sIDfilePath), True)
        IO.File.Copy(IO.Path.Combine(IO.Directory.GetCurrentDirectory, "notes.ini"), IO.Path.Combine(notesPath, "notes.ini"), True)
        WritePrivateProfileString("Notes", "KeyFilename", IO.Path.Combine(notesDataPath, sIDfilePath), IO.Path.Combine(notesPath, "notes.ini"))
        WritePrivateProfileString("Notes", "MailFile", sPfile, IO.Path.Combine(notesPath, "notes.ini"))
 
        domS = CreateObject("lotus.NotesSession")
 
 
        Call domS.Initialize(sPpassword)
        'System.Threading.Thread.Sleep(2000)
 
        'domDir = domS.GetDbDirectory(sPserver)
        'domDB = domDir.OpenMailDatabase()
        domDB = domS.GetDatabase(sPserver, sPfile)
        'domDir = domS.GetDbDirectory(sPserver).OpenMailDatabase
 
        'System.Threading.Thread.Sleep(2000)
 
 
        Return True
 
    End Function
 
    Public Sub close()
 
        domDB = Nothing
        domS = Nothing
 
        GC.Collect()
        GC.WaitForPendingFinalizers()
 
    End Sub

Open in new window

Avatar of SysExpert
SysExpert
Flag of Israel image

What version of the client is being used ?

Maybe a newer version will work better ?

Avatar of Hoboly
Hoboly

ASKER

lotus notes 6.5.4
Avatar of Hoboly

ASKER

Cannot create ActiveX component.
at Microsoft.VisualBasic.Interaction.CreateObject(String ProgId, String ServerName)

        domS = CreateObject("lotus.NotesSession")
        Call domS.Initialize(sPpassword)
        domDB = domS.GetDatabase(sPserver, sPfile)
 
 after few hours.
Two questions:
1) If Notes is open, does it still function? If so, there's little to clean up in Notes.
2) Are you sure your function close() is called after every open(), and that there is no error handling preventing the close() to happen?

Suggestion: create a class around these functions, and use the close-function inside the Delete .
ASKER CERTIFIED SOLUTION
Avatar of Bill-Hanson
Bill-Hanson
Flag of United States of America image

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