I'm creating a new Notes mail message from .NET using the code below. It seems to work fine and creates a new memo and leaves it open in edit mode but if you are not a Lotus Notes Administrator, it also throws an exception at the end, even though it's worked fine? Any ideas why?
Public Function CreateMail(ByVal Recipient As Collection) As Boolean
Dim Addresses As New StringBuilder
Dim i As Integer
Dim NotesSession As Object
Dim NotesDb As Object
Dim NotesDoc As Object
Dim NotesWorkspace As Object
Dim ParametersGetDb() As String = {"", m_UserMailFile}
Dim ParametersEditDoc() As Object = {"True", ""}
'get the email addresses
For i = 1 To Recipient.Count
Addresses.Append(Recipient.Item(i))
Addresses.Append(",")
Next
'start a new Notes Session
m_DominoSession = Nothing
NotesSession = CreateObject("Notes.NotesSession")
'get the user notes database
If Not (NotesSession Is Nothing) Then
NotesDb = CallByName(NotesSession, "GetDatabase", CallType.Method, ParametersGetDb)
'open user mail database
If Not (NotesDb Is Nothing) Then
CallByName(NotesDb, "OpenMail", CallType.Method)
'create new document
NotesDoc = CallByName(NotesDb, "CreateDocument", CallType.Method)
If Not (NotesDoc Is Nothing) Then
'set some parameters
CallByName(NotesDoc, "Form", CallType.Set, "Memo")
CallByName(NotesDoc, "SendTo", CallType.Set, Addresses.ToString)
ParametersEditDoc.SetValue(NotesDoc, 1)
'create a NotesUIWorkspace
NotesWorkspace = CreateObject("Notes.NotesUIWorkspace")
'open the new memo previously created
If Not (NotesWorkspace) Is Nothing Then
CallByName(NotesWorkspace, "EditDocument", CallType.Method, ParametersEditDoc)
NotesSession = Nothing
NotesDb = Nothing
NotesDoc = Nothing
NotesWorkspace = Nothing
Addresses = Nothing
Return True
End If
End If
End If
End If
End Function
Public Function CreateMail(ByVal Recipient As Collection) As Boolean
Dim Addresses As New StringBuilder
Dim i As Integer
Dim NotesSession As Object
Dim NotesDb As Object
Dim NotesDoc As Object
Dim NotesWorkspace As Object
Dim ParametersGetDb() As String = {"", m_UserMailFile}
Dim ParametersEditDoc() As Object = {"True", ""}
'get the email addresses
For i = 1 To Recipient.Count
Addresses.Append(Recipient.Item(i))
Addresses.Append(",")
Next
'start a new Notes Session
m_DominoSession = Nothing
NotesSession = CreateObject("Notes.NotesSession")
'get the user notes database
If Not (NotesSession Is Nothing) Then
NotesDb = CallByName(NotesSession, "GetDatabase", CallType.Method, ParametersGetDb)
'open user mail database
If Not (NotesDb Is Nothing) Then
CallByName(NotesDb, "OpenMail", CallType.Method)
'create new document
NotesDoc = CallByName(NotesDb, "CreateDocument", CallType.Method)
If Not (NotesDoc Is Nothing) Then
'set some parameters
CallByName(NotesDoc, "Form", CallType.Set, "Memo")
CallByName(NotesDoc, "SendTo", CallType.Set, Addresses.ToString)
ParametersEditDoc.SetValue(NotesDoc, 1)
'create a NotesUIWorkspace
NotesWorkspace = CreateObject("Notes.NotesUIWorkspace")
'open the new memo previously created
If Not (NotesWorkspace) Is Nothing Then
CallByName(NotesWorkspace, "EditDocument", CallType.Method, ParametersEditDoc)
NotesSession = Nothing
NotesDb = Nothing
NotesDoc = Nothing
NotesWorkspace = Nothing
Addresses = Nothing
Return True
End If
End If
End If
End If
End Function