Lotus Notes GetDatabase 参数将如何影响我的笔记帐户?

How will affect Lotus Notes GetDatabase parameters my notes account?

我想用 excel 宏发送电子邮件。我在一些网站上看到了同样简单的 VBA 代码,可以发送带附件的电子邮件。

Sub Send_Email_via_Lotus_Notes()
    Dim Maildb As Object
    Dim MailDoc As Object
    Dim Body As Object
    Dim Session As Object
    'Start a session of Lotus Notes
        Set Session = CreateObject("Lotus.NotesSession")
    'This line prompts for password of current ID noted in Notes.INI
        Call Session.Initialize
    'or use below to provide password of the current ID (to avoid Password prompt)
        'Call Session.Initialize("<password>")
    'Open the Mail Database of your Lotus Notes
        Set Maildb = Session.GETDATABASE("", "D:\Notes\data\Mail\eXceLiTems.nsf")
        If Not Maildb.IsOpen = True Then Call Maildb.Open
    'Create the Mail Document
        Set MailDoc = Maildb.CREATEDOCUMENT
        Call MailDoc.REPLACEITEMVALUE("Form", "Memo")
    'Set the Recipient of the mail
        Call MailDoc.REPLACEITEMVALUE("SendTo", "Ashish Jain")
    'Set subject of the mail
        Call MailDoc.REPLACEITEMVALUE("Subject", "Subject Text")
    'Create and set the Body content of the mail
        Set Body = MailDoc.CREATERICHTEXTITEM("Body")
        Call Body.APPENDTEXT("Body text here")
    'Example to create an attachment (optional)
        Call Body.ADDNEWLINE(2)
        Call Body.EMBEDOBJECT(1454, "", "C:\dummy.txt", "Attachment")
    'Example to save the message (optional) in Sent items
        MailDoc.SAVEMESSAGEONSEND = True
    'Send the document
    'Gets the mail to appear in the Sent items folder
        Call MailDoc.REPLACEITEMVALUE("PostedDate", Now())
        Call MailDoc.SEND(False)
    'Clean Up the Object variables - Recover memory
        Set Maildb = Nothing
        Set MailDoc = Nothing
        Set Body = Nothing
        Set Session = Nothing
End Sub

设置 Maildb = Session.GETDATABASE("", "D:\Notes\data\Mail\eXceLiTems.nsf") 在我工作的笔记本电脑上有 10 个 nsf 文件。我不知道应该在第二个参数中输入哪个。 我在这里阅读了语法:https://help.hcltechsw.com/dom_designer/9.0.1/appdev/H_GETDATABASE_METHOD.html

都可以为空字符串。如果我使用空字符串,如果我是正确的,它会创建一个新数据库。因为我想每天发送 5 封电子邮件,所以我想在 for 循环中发送电子邮件。如果我使用空字符串,代码将每天创建 5 个数据库?我想是的,所以我想我需要使用 10 个 nsf 文件之一作为第二个参数,所以它不会创建,但我不想因此而使我的笔记帐户崩溃。 我对笔记很陌生。我用vba for outlook发邮件,没有数据库参数。

首先:GetDatabase 绝不会创建新数据库。如果你输入的数据库存在,那么你的OBJECT(不是真实的东西,只是一个变量)将被创建并且isOpen-属性为真,否则为假。

您需要决定要(至少暂时)存储您要发送的邮件的位置。

如果你设置 SaveMessageOnSend = True 那么它将保存在那个数据库中,如果你将它设置为 False,那么它只会在内存中创建并且不会保存,但是你仍然需要一个容器来“在内存中” "- 文件。

通常以编程方式创建的邮件将保存在用户的邮件文件中(在这种情况下:在您的邮件文件中。

正确的代码是:

'Initialize object without really opening a database
Set Maildb = Session.GETDATABASE("", "")
'Now open the users' mailfile
Call Maildb.OpenMail

如果您有一些“虚拟”数据库来创建您的邮件,那么您需要在 运行 您的脚本之前(在 Notes\Data - 目录中)使用您的 Notes 客户端创建该数据库并打开那个:

如果你在 Notes\Data 的 mail- 子目录中创建它,然后它可能具有如下绝对路径:

C:\Program Files (x86)\HCL\Notes\Data\mail\dummy.nsf

在您的脚本中,您可以使用相对路径(从数据开始)对其进行寻址:

Set Maildb = Session.GETDATABASE("", "mail\dummy.nsf")

或绝对路径(并不重要),如:

Set Maildb = Session.GETDATABASE("", "C:\Program Files (x86)\HCL\Notes\Data\mail\dummy.nsf")

在这种情况下不需要“OpenMail”命令,因为您不想使用用户的邮件文件,而是明确给出的邮件文件...

还有一件事:Call MailDoc.SEND(False) 已经在您的邮件上创建了一个 PostedDate- 项目。无需使用行 Call MailDoc.REPLACEITEMVALUE("PostedDate", Now()).