My company recently upgraded from Lotus Notes 8.5 to IBM Notes 9.0. This has thrown a wrench into the code shown below, which I is floating around online and was functional until now. The code is meant to send an email with an attachment through the Notes client. If the client is closed, it will automatically open and prompt for credentials before sending the email; if open, it will automatically send the email.
A number of issues arise that I haven’t been able to recognize a pattern in. In some cases, the emails send without a hitch, but in others, the code causes Notes to bug out and close or throws an error (The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).
In researching this error, the only results I find have to do with Excel. I have also had no luck researching this general subject elsewhere.
Please help.
'Set up the objects required for Automation into lotus notes
Dim Maildb As Object 'The mail database
Dim UserName As String 'The current users notes name
Dim MailDbName As String 'THe current users notes mail database name
Dim MailDoc As Object 'The mail document itself
Dim AttachME As Object 'The attachment richtextfile object
Dim Session As Object 'The notes session
Dim EmbedObj As Object 'The embedded object (Attachment)
'Start a session to notes
plsWaitFrm.Show()
Try
Session = CreateObject(“Notes.NotesSession”)
'Get the sessions username and then calculate the mail file name
'You may or may not need this as for MailDBname with some systems you
'can pass an empty string
UserName = Session.UserName
MailDbName = Microsoft.VisualBasic.Left(UserName, 1) & Microsoft.VisualBasic.Right(UserName, (Len(UserName) - InStr(1, UserName, " “))) & “.nsf”
'Open the mail database in notes
Maildb = Session.GETDATABASE(”", MailDbName)
If Maildb.IsOpen = True Then
'Already open for mail
Else
Maildb.OPENMAIL()
End If
'Set up the new mail document
MailDoc = Maildb.CREATEDOCUMENT
MailDoc.Form = “Memo”
Dim recipients(ToRecipients.Count - 1) As String
For i As Integer = 0 To ToRecipients.Count - 1 Step 1
recipients(i) = ToRecipients(i)
Next
Dim copies(CcRecipients.Count - 1) As String
For i As Integer = 0 To CcRecipients.Count - 1 Step 1
copies(i) = CcRecipients(i)
Next
'Dim recipient As String = String.Join(", “, ToRecipients)
'recipient = recipient & “,”
'Dim copies As String = String.Join(”, ", CcRecipients)
'copies = copies & “,”
'MailDoc.sendto = recipient
MailDoc.CopyTo = copies
MailDoc.Subject = txtBxSubject.Text
MailDoc.Body = txtBxBody.Text
MailDoc.SAVEMESSAGEONSEND = saveit
'Set up the embedded object and attachment and attach it
If attachment <> “” Then
AttachME = MailDoc.CREATERICHTEXTITEM(“Attachment”)
EmbedObj = AttachME.EMBEDOBJECT(1454, “”, attachment, “Attachment”)
'MailDoc.CREATERICHTEXTITEM(“Attachment”)
End If
'Send the document
MailDoc.PostedDate = Now() 'Gets the mail to appear in the sent items folder
MailDoc.SEND(0, recipients)
Dim attachmentName As String = Path.GetFileName(attachment)
Dim recipientNames As New List(Of String)
Dim copyNames As New List(Of String)
For Each Contact In contactListLocal.Contacts
If Contact.EmailTo = True Then recipientNames.Add(Contact.First & " " & Contact.Last)
If Contact.EmailCC = True Then copyNames.Add(Contact.First & " " & Contact.Last)
Next
MsgBox(“Email message sent!” & vbCr & vbCr & “To: " & String.Join(”, ", recipientNames) & vbCr & vbCr & “Cc: " & String.Join(”, ", copyNames) & vbCr & vbCr & "Attachment: " & attachmentName, MsgBoxStyle.OkOnly, “AzTech Satellite Share App”)
Catch ex As Exception
ErrorHandler.Helpers.LogMessage(ex.Message)
MsgBox(“An error occurred sending your email. Please contact AzTech IT for help.”, MsgBoxStyle.OkOnly, “AzTech Satellite Share App”)
Finally
'Clean Up
Maildb = Nothing
MailDoc = Nothing
AttachME = Nothing
Session = Nothing
EmbedObj = Nothing
'RaiseEvent EmailSent()
'plsWaitFrm.Close()
plsWaitFrm.Hide()
End Try