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



更新时间:2022年3月28日:我找到了一个适合我的解决方案。下面的代码现在可以工作了。电子邮件只有在即时发送时才保存/不保存。

我的(旧(问题是:

我想使用以下代码通过IBMNotes发送电子邮件。一切都很好,但我不知道如何不把电子邮件保存在文件夹中;发送";。

我已经试着把线

.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

这就是您正在做的:

  • 建筑文档1
  • 处理doc1.uidocument
  • 发送doc1.uidocument.document(=doc2(

SaveMessageOnSend应用于doc1,而不是uidoc或doc2。

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

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

尝试将SaveOptions设置为"0";而不是零。

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

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

最新更新