title: Sending IBM Notes Mail 9.0.1
body: <p>Lotus Notes just updated and became IBM Notes 9.0.1 causing code I've written to send an email with an attachment to fail. Here's the code:</p>
  
  <pre><code>Public Sub SendNotesMail(ByVal attachment As String, ByVal ToRecipients As List(Of String), ByVal CcRecipients As List(Of String), ByVal saveit As Boolean)
      '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) &amp; Microsoft.VisualBasic.Right(UserName, (Len(UserName) - InStr(1, UserName, " "))) &amp; ".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 &amp; ","
          'Dim copies As String = String.Join(", ", CcRecipients)
          'copies = copies &amp; ","
          '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 &lt;&gt; "" Then
              AttachME = MailDoc.CREATERICHTEXTITEM("Attachment")
              EmbedObj = AttachME.EMBEDOBJECT(1454, "", attachment, "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 &amp; " " &amp; Contact.Last)
              If Contact.EmailCC = True Then copyNames.Add(Contact.First &amp; " " &amp; Contact.Last)
          Next
          MsgBox("Email message sent!" &amp; vbCr &amp; vbCr &amp; "To: " &amp; String.Join(", ", recipientNames) &amp; vbCr &amp; vbCr &amp; "Cc: " &amp; String.Join(", ", copyNames) &amp; vbCr &amp; vbCr &amp; "Attachment: " &amp; 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
  
  End Sub
  </code></pre>
  
  <p>The line causing this error: 6/12/2015 20:30:39  : The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)) is:</p>
  
  <p>MailDoc.CREATERICHTEXTITEM("Attachment")</p>
  
  <p>Without any suggestions from Intellisense, and knowing next to nothing about the inner workings of Notes, I'm completely in the dark with this code. Does anyone have a clue what needs to change?</p>
  
  <p><strong>EDIT</strong>
  As suggested, I removed the code creating the second attachment - MailDoc.CREATERICHTEXTITEM("Attachment"). The email does now send, but the code still throws the above error at MailDoc.SEND(0, recipients).</p>
  
  <p><strong>EDIT #2</strong>
  The emails do send, but occassionally the messages are sent twice, and at other times Notes crashes.</p>
  
  <p>Is there really no one else who has this issue or that can make a recommendation?</p>