Lotus Notes VBA 电子邮件自动化 - db.CreateDocument 命令失败
Lotus Notes VBA Email Automation - db.CreateDocument Command Fail
我正在尝试使用 VBA 通过 Lotus Notes 9.0 自动发送电子邮件。该代码将加载注释,它要求我输入密码,但在密码提示出现之前,我收到一个错误。我 运行 中的错误是 "Run-time error '-2147417851 (80010105)': Automation Error The server threw an exception" 当我点击调试时,它失败的行是 "Set obDoc = obDB.CreateDocument"。我在网上看到的很多示例都与我在代码中所做的相匹配,所以我不确定问题出在哪里。
代码如下:
Sub Send_Emails()
Dim stSubject As Variant
Dim emailList As Variant
Dim obSess As Object
Dim obDB As Object
Dim obDoc As Object
'----Create Email List - separate function, dynamically creates email list based off report processing done in other functions
CreateEmailList
'----Info for Subject
stSubject = "test subject"
'----Create Notes Session
Set obSess = CreateObject("Notes.NotesSession")
Set obDB = obSess.GETDATABASE("", "")
If obDB.IsOpen = False Then
Call obDB.OPENMAIL
End If
'----Create the e-mail - **FAILURE OCCURS HERE**
Set obDoc = obDB.CreateDocument
'----Add values to the email
With obDoc
.form = "Memo"
.SendTo = "test@test.com"
.blindcopyTo = emailList
.Subject = stSubject
.HTMLBody = "<HTML><BODY><p>test</p></BODY></HTML>"
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, emailList
End With
'----Clean Up
Set obDoc = Nothing
Set obDB = Nothing
Set obSess = Nothing
MsgBox "The e-mail has been sent successfully", vbInformation
End Sub
您提到您正在使用 Notes 9,所以我查看了 Notes 9.01 的联机帮助,help page for the OpenMail method 说
Note: This method is supported in LotusScript® only. For COM, use OpenMailDatabase in NotesDbDirectory.
现在,您实际上使用的是 OLE 自动化 classes(植根于 Notes.NotesSession),而不是 COM classes(植根于 Lotus.NotesSession),所以我不知道您是否可以使用 NotesDbDirectory class,但打开当前用户邮件数据库的另一种方法是调用 NotesSession.GetEnvironmentString("MailServer",true) 和NotesSession.GetEnvironmentString("MailFile",true),并将它们用作调用 GetDatabase 的值。
我正在尝试使用 VBA 通过 Lotus Notes 9.0 自动发送电子邮件。该代码将加载注释,它要求我输入密码,但在密码提示出现之前,我收到一个错误。我 运行 中的错误是 "Run-time error '-2147417851 (80010105)': Automation Error The server threw an exception" 当我点击调试时,它失败的行是 "Set obDoc = obDB.CreateDocument"。我在网上看到的很多示例都与我在代码中所做的相匹配,所以我不确定问题出在哪里。
代码如下:
Sub Send_Emails()
Dim stSubject As Variant
Dim emailList As Variant
Dim obSess As Object
Dim obDB As Object
Dim obDoc As Object
'----Create Email List - separate function, dynamically creates email list based off report processing done in other functions
CreateEmailList
'----Info for Subject
stSubject = "test subject"
'----Create Notes Session
Set obSess = CreateObject("Notes.NotesSession")
Set obDB = obSess.GETDATABASE("", "")
If obDB.IsOpen = False Then
Call obDB.OPENMAIL
End If
'----Create the e-mail - **FAILURE OCCURS HERE**
Set obDoc = obDB.CreateDocument
'----Add values to the email
With obDoc
.form = "Memo"
.SendTo = "test@test.com"
.blindcopyTo = emailList
.Subject = stSubject
.HTMLBody = "<HTML><BODY><p>test</p></BODY></HTML>"
.SaveMessageOnSend = True
.PostedDate = Now()
.Send 0, emailList
End With
'----Clean Up
Set obDoc = Nothing
Set obDB = Nothing
Set obSess = Nothing
MsgBox "The e-mail has been sent successfully", vbInformation
End Sub
您提到您正在使用 Notes 9,所以我查看了 Notes 9.01 的联机帮助,help page for the OpenMail method 说
Note: This method is supported in LotusScript® only. For COM, use OpenMailDatabase in NotesDbDirectory.
现在,您实际上使用的是 OLE 自动化 classes(植根于 Notes.NotesSession),而不是 COM classes(植根于 Lotus.NotesSession),所以我不知道您是否可以使用 NotesDbDirectory class,但打开当前用户邮件数据库的另一种方法是调用 NotesSession.GetEnvironmentString("MailServer",true) 和NotesSession.GetEnvironmentString("MailFile",true),并将它们用作调用 GetDatabase 的值。