如何决定是否通过 IBM Notes 保存电子邮件?

How can I decide whether to save or not save an email via IBM Notes?

2022 年 3 月 28 日更新: 我找到了一个解决方案,对我来说很好。下面的代码现在可以工作了。电子邮件仅在立即发送时 saved/not 保存。

我的(老)问题是:

我想使用以下代码通过 IBM Notes 发送电子邮件。一切正常,但我不知道如何不将电子邮件保存在“已发送”文件夹中。

我已经试过放线了

.PostedDate = Now()

在“objBackendDocument”对象上,并尝试清除该值,因为我在一些帖子中读到,这可能是 IBM Notes 将电子邮件保存在“已发送”文件夹中的条件。但是没用。

如果我使用替代邮件文件,它根本不会保存我的电子邮件。如果我使用我的标准邮件文件,它会在保存每封电子邮件时忽略“blnSaveEMail”。

我不想保存电子邮件,因为我想发送带有附件的自动电子邮件,这些附件已经在用户的电脑上(节省存储空间并避免副本的副本)。

另一个想法可能是从最近发送的电子邮件中删除附件,但目前这对我来说很难。因为我仍在尝试了解 IBM Notes 的 API 是如何工作的。 :)

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'+
'+  EMail_by_Notes
'+
'+  API: Lotus Notes COM/OLE
'+  Parameter "varRecipients": Requires a VARIANT or an array (VARIANT) of verified email-adresses
'+  Parameter "strSubject": Requires a STRING as the title of the email
'+  Paramater "strMessage": Requires as STRING as the content of the email
'+  Parameter "varCopy" optional: VARIANT or an array (VARIANT) of verified email-adresses
'+  Parameter "varBlindCopy" optional: VARIANT or an array (VARIANT) of verified email-adresses
'+  Parameter "varAttachements" optional: VARIANT or an array (VARIANT) of filepath(s)
'+  Parameter "blnSendImmediately" optional: BOOLEAN
'+  Parameter "blnSaveEMail" optional: BOOLEAN
'+  Parameter "strAlternative_Mailfile" optional: STRING, contains the filename of the alternative mailfile
'+
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    Public Function EMail_by_Notes( _
        varRecipients As Variant, _
        strSubject As String, _
        strMessage As String, _
        Optional varCopy As Variant = "", _
        Optional varBlindCopy As Variant = "", _
        Optional varAttachements As Variant, _
        Optional blnSendImmediately As Boolean = True, _
        Optional blnSaveEMail As Boolean = False, _
        Optional strAlternative_Mailfile As String = "" _
            ) As Boolean
    
        Dim objNotesSession As Object
        Dim objNotesWorkspace As Object
        Dim objNotesDatabase As Object
        
        Dim objBackendDocument As Object
        Dim objFrontendDocument As Object
        
        Dim objRecipients As Object
        Dim objCopy As Object
        Dim objBlindCopy As Object
        Dim objSubject As Object
        Dim objMessage As Object
        Dim objEmbedded As Object
        Dim objAttachement As Object
        Dim objProfileDoc As Object

        Dim strMailServer As String
        Dim strMailFile As String
        Dim strFilepath As String
        Dim strSignature As String
        
        Dim lngIndex As Long
        
'Starts Notes Session
    
        Set objNotesSession = CreateObject("Notes.NotesSession")
    
'Locate the mailserver
    
        strMailServer = objNotesSession.GetEnvironmentString("MailServer", True)

'Check for an alternative mailfile (in case you have a second account)
    
        If VBA.Len(strAlternative_Mailfile) = 0 Then
    
'Uses the standard account
    
            strMailFile = objNotesSession.GetEnvironmentString("MailFile", True)
            
        Else
    
'Uses an alternative mailfile, if the filename is wrong, it uses the standard account
'Unfortunately there is no error message
    
            strMailFile = "mail/" & strAlternative_Mailfile
            
        End If
    
'Connect to the database
    
        Set objNotesDatabase = objNotesSession.GETDATABASE(strMailServer, strMailFile)
    
'If your constructed path (variable strMailFile) is wrong or the database cannot be accessed
'then this line will make sure to fallback to the mailfile configured in your location document in Notes Client.
    
        If Not objNotesDatabase.IsOpen Then objNotesDatabase.OPENMAIL
        
        If blnSendImmediately = True Then

            Set objProfileDoc = objNotesDatabase.GetProfileDocument("CalendarProfile")

        End If
        
'Create a Notes document in the backend
    
        Set objBackendDocument = objNotesDatabase.CREATEDOCUMENT
            
        With objBackendDocument
    
'Fill in the contents
    
            Set objRecipients = .APPENDITEMVALUE("SendTo", varRecipients)
            Set objCopy = .APPENDITEMVALUE("CopyTo", varCopy)
            Set objBlindCopy = .APPENDITEMVALUE("BlindCopyTo", varBlindCopy)
            Set objSubject = .APPENDITEMVALUE("Subject", strSubject)
                                
    
            If blnSendImmediately = True Then

                Set objMessage = .CreateRichTextItem("body")

'Adds the user's RTF-signature from Lotus Notes
                
                With objMessage
                    .appendText strMessage & VBA.vbCrLf & VBA.vbCrLf
                    .appendrtitem objProfileDoc.GetfirstItem("Signature_Rich")
                End With
                
            End If
    
'Attach the file(s)
            
            If VBA.IsMissing(varAttachements) = False Then
            
                If VBA.IsArray(varAttachements) = True Then
                
                    For lngIndex = LBound(varAttachements) To UBound(varAttachements)
                    
                        strFilepath = varAttachements(lngIndex)
                        
                        If strFilepath <> "" And VBA.Dir(strFilepath) <> "" Then
                        
                            Set objAttachement = .CreateRichTextItem("Attachment" & lngIndex)
                            Set objEmbedded = _
                                objAttachement.EMBEDOBJECT(1454, "", strFilepath, "Attachment" & lngIndex)
                                
                        End If
                        
                    Next
                
                ElseIf VBA.Len(varAttachements) > 0 And VBA.Dir(varAttachements) <> "" Then
                
                    Set objAttachement = .CreateRichTextItem("Attachment1")
                    Set objEmbedded = _
                        objAttachement.EMBEDOBJECT(1454, "", varAttachements, "Attachment1")
                
                End If
                
            End If
            
'Save or do not save the email in the folder "sent" before sending the email immediately

            If blnSendImmediately = True Then .SAVEMESSAGEONSEND = blnSaveEMail
            
        End With

'Check, whether the email shall be sent immediately or not
    
        If blnSendImmediately = False Then
        
'Load Notes Workspace
        
            Set objNotesWorkspace = CreateObject("Notes.NotesUIWorkspace")
           
'Get the backend document in the foreground
'Also in case, the email shall be edited before sending it
        
            Set objFrontendDocument = objNotesWorkspace.EDITDOCUMENT(True, objBackendDocument)
               
            With objFrontendDocument
            
'Fill in the emails message
'Important if you use a signature in IBM Notes
        
                .GoToField "Body"
                .InsertText strMessage
                
            End With
        
        Else
        
            With objBackendDocument
                .Send False
            End With
                
        End If

        EMail_by_Notes = True
        
    End Function

尝试将 SaveOptions 设置为“0”而不是零。

在我脑海的深处,有什么东西告诉我它应该是一个文本值。

此外,我认为您应该在打开 UIDocument 进行编辑之前执行此操作,但那是一个更加模糊的记忆。

这就是你正在做的事情:

  • building doc1
  • 致力于doc1.uidocument
  • 发送doc1.uidocument.document (=doc2)

SaveMessageOnSend 适用于 doc1,不适用于 uidoc 或 doc2。

此外,在ui中打开并在后面发送是没有意义的。

您应该在后台完成所有操作(在其配置文件中查找用户签名)。 如果你想与用户交互,在前台打开,让他工作并选择保存或不保存邮件(这是一个全局的 Notes 客户端首选项,可以用字段 MailSaveOptions)