I am writing a VB2005 application that will automatically generate emails and display them to the end user (eventually, these will have reports attached to them). Here’s my code:
'######### BEGIN CODE ############
Private Sub BuildLotusNotesObject()
Dim nSession As New NotesSession
Dim nDatabase As NotesDatabase
Dim nDocument As NotesDocument
Dim nRTItem As NotesRichTextItem
If Not (nSession Is Nothing) Then
'start a new notes session
nSession.Initialize()
'get the database based on the current user info
Dim server As String = nSession.GetEnvironmentString("MailServer", True) 'Get user's home/mail server
Dim mailfile As String = nSession.GetEnvironmentString("MailFile", True) 'Get user's mail file name
nDatabase = nSession.GetDatabase(server, mailfile, False)
'proceed only if the previous GetDatabase call worked
If Not (nDatabase Is Nothing) Then
'generate a notes Memo to send as an email
nDocument = nDatabase.CreateDocument()
nDocument.ReplaceItemValue("Form", "Memo")
nDocument.ReplaceItemValue("SendTo", Me.MailTo)
nDocument.ReplaceItemValue("CopyTo", Me.m_mailCC)
nDocument.ReplaceItemValue("BlindCopyTo", Me.m_mailBCC)
nDocument.ReplaceItemValue("Subject", Me.MailSubject)
'Create the message body
nRTItem = nDocument.CreateRichTextItem("Body")
'append the user supplied text
nRTItem.AppendText(Me.MailBody)
'display the email
nDocument.Save(True, False)
Process.Start(nDocument.NotesURL)
Else
'GetDatabase call failed
Throw New Exception("Could not retrieve notes database")
End If
End If
nSession = Nothing
nDatabase = Nothing
nDocument = Nothing
nRTItem = Nothing
End Sub
'######### END CODE ############
This code works fine on notes 6.0.2 for me and for the customer. The customer has multiple versions of Notes 6.X running in their facility though. On 6.0.4, the process fails for both of us. the line:
'append the user supplied text
nRTItem.AppendText(Me.MailBody)
is throwing a System.AccessViolationException. The exception message says “Attempted to read or write protected memory. This is often an indication that other memory is corrupt.” Any ideas what i would need to do to fix this? Again, it works fine in 6.0.2 :-\