发送IBM Notes Mail 9.0.1

时间:2015-06-12 18:42:30

标签: vb.net lotus-notes

Lotus Notes刚刚更新并成为IBM Notes 9.0.1,导致我编写的代码发送带有附件失败的电子邮件。这是代码:

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) & 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")
        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

End Sub

导致此错误的行:6/12/2015 20:30:39:服务器引发了异常。 (来自HRESULT的异常:0x80010105(RPC_E_SERVERFAULT))是:

MailDoc.CREATERICHTEXTITEM(&#34;附件&#34)

如果没有来自Intellisense的任何建议,并且对Notes的内部工作几乎一无所知,我完全不知道这段代码。有没有人知道需要改变什么?

修改 按照建议,我删除了创建第二个附件的代码 - MailDoc.CREATERICHTEXTITEM(&#34; Attachment&#34;)。电子邮件现在发送,但代码仍然在MailDoc.SEND(0,收件人)抛出上述错误。

编辑#2 电子邮件会发送,但偶尔会发送两次消息,有时会发送消息。

是否真的没有其他人有此问题或可以提出建议?

1 个答案:

答案 0 :(得分:1)

你有两行调用Maildoc.CreateRichTextItem。他们都试图创建一个名为&#34;附件&#34;的项目。它是引发错误的第一个还是第二个?我的猜测是它是第二个,它正在有效地尝试创建一个已经存在的项目。这当然不是正常的做法,我无法想到任何人会以这种方式编码的原因。所以最有可能的是,无论您以前处理过哪种类型的Notes编码,都可能忽略了添加重复项的尝试,但是较新版本的Notes API会将其检测为错误。

请注意,创建一个名为&#34; attachment&#34;的单独NotesRichTextItem也不是很正常。仅用于电子邮件附件。它有效,但它可能不会像你期望的那样。通常的方法是将它附加到名为&#34; Body&#34;的NotesRichTextItem。您的代码正在使用名为&#34; Body&#34;的纯文本项。相反,对于任何编码,这可能并不知道它可能是富文本,并且相同的项目可以存储附件。