我对 Lotus Script 或 Notes/Domino 的了解很少,但我有一个很久以前从某处复制的过程,它允许我通过 VBA 通过 Notes 发送电子邮件。我通常只将其用于内部通知,其中格式并不重要。
我现在想用它向客户发送外部电子邮件,而企业类型更希望电子邮件符合我们的风格指南(基本上是无衬线字体)。
我正要告诉他们该代码仅适用于纯文本,但后来我注意到该例程确实引用了某种 CREATERICHTEXTITEM 对象。这是否意味着我可以在将正文字符串传递到邮件例程之后对其应用某种格式?除了维护我们宝贵的品牌价值之外,这对于我突出显示电子邮件中的某些段落也非常方便。
我对“网络”进行了深入研究,看看这段代码是否可以改编,但由于不熟悉 Notes 的对象模型,而且在线 Notes 资源似乎反映了应用程序本身的迟钝性,这意味着我并没有得到很好的帮助。远的。
代码:
Sub sendEmail(EmailSubject As String, EMailSendTo As String, EMailBody As String, MailServer as String)
Dim objNotesSession As Object
Dim objNotesMailFile As Object
Dim objNotesDocument As Object
Dim objNotesField As Object
Dim sendmail As Boolean
'added for integration into reporting tool
Dim dbString As String
dbString = "mail\" & Application.UserName & ".nsf"
On Error GoTo SendMailError
'Establish Connection to Notes
Set objNotesSession = CreateObject("Notes.NotesSession")
On Error Resume Next
'Establish Connection to Mail File
Set objNotesMailFile = objNotesSession.GETDATABASE(MailServer, dbString)
'Open Mail
objNotesMailFile.OPENMAIL
On Error GoTo 0
'Create New Memo
Set objNotesDocument = objNotesMailFile.createdocument
Dim oWorkSpace As Object, oUIdoc As Object
Set oWorkSpace = CreateObject("Notes.NotesUIWorkspace")
Set oUIdoc = oWorkSpace.CurrentDocument
'Create 'Subject Field'
Set objNotesField = objNotesDocument.APPENDITEMVALUE("Subject", EmailSubject)
'Create 'Send To' Field
Set objNotesField = objNotesDocument.APPENDITEMVALUE("SendTo", EMailSendTo)
'Create 'Copy To' Field
Set objNotesField = objNotesDocument.APPENDITEMVALUE("CopyTo", EMailCCTo)
'Create 'Blind Copy To' Field
Set objNotesField = objNotesDocument.APPENDITEMVALUE("BlindCopyTo", EMailBCCTo)
'Create 'Body' of memo
Set objNotesField = objNotesDocument.CREATERICHTEXTITEM("Body")
With objNotesField
.APPENDTEXT emailBody
.ADDNEWLINE 1
End With
'Send the e-mail
Call objNotesDocument.Save(True, False, False)
objNotesDocument.SaveMessageOnSend = True
'objNotesDocument.Save
objNotesDocument.Send (0)
'Release storage
Set objNotesSession = Nothing
Set objNotesMailFile = Nothing
Set objNotesDocument = Nothing
Set objNotesField = Nothing
'Set return code
sendmail = True
Exit Sub
SendMailError:
Dim Msg
Msg = "Error # " & Str(Err.Number) & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox Msg, , "Error", Err.HelpFile, Err.HelpContext
sendmail = False
End Sub