我尝试编码通过电子邮件发送Rich文本字段,但我发现错误,我认为这种方法可以通过以下代码发送电子邮件
Sub Click(Source As Button)
Dim s As New NotesSession
Dim w As New NotesUIWorkspace
Dim db As NotesDatabase
Dim doc As NotesDocument
Dim uidoc As NotesUIDocument
Set uidoc = w.CurrentDocument
Set s = New NotesSession
Set w = New NotesUIWorkspace
Set db = s.CurrentDatabase
Set doc = New NotesDocument (db)
doc.sendTo =s.UserName
doc.Subject = "Employee Information"
Dim rt As NotesRichTextItem
Set rt = New NotesRichTextItem ( doc, "Body" )
'Dim file As Variant 'if I use this code for declare for get value; Error : Type Mismatch
'Set file = doc.GetFirstItem("Body")
Dim rtitem As NotesRichTextItem 'if I use this code for declare for get value ; Error : Missing text object
Set rtitem = doc.GetFirstItem( "Body" )
Call rt.AppendRTItem(rtitem)
doc.Send(False)
End Sub
答案 0 :(得分:0)
我注意到的一件事是您没有在正在创建的邮件文档上设置表单。
你有一些你不需要的代码,因为你不在任何地方使用uidoc,不需要或者声明一个NotesUIWorkspace对象。 我还建议您使用更好的变量名,而不要在NotesDocument对象中设置字段值时使用扩展表示法。
我建议你看一下这里的文章:
http://blog.texasswede.com/how-to-write-better-code-in-notesdomino/
以下是我清理的代码:
Option Public
Option Declare
Sub Click(Source As Button)
Dim session As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim mailDoc As NotesDocument
Dim mailBody As NotesRichTextItem
Set db = session.CurrentDatabase
Set mailDoc = New NotesDocument(db)
Call mailDoc.ReplaceItemValue("Form","Memo")
Call mailDoc.ReplaceItemValue("SendTo",session.UserName)
Call mailDoc.ReplaceItemValue("Subject","Employee Information")
Set mailBody = New NotesRichTextItem(mailDoc,"Body" )
'Dim file As Variant 'if I use this code for declare for get value; Error : Type Mismatch
'Set file = doc.GetFirstItem("Body")
Dim rtitem As NotesRichTextItem 'if I use this code for declare for get value ; Error : Missing text object
Set rtitem = doc.GetFirstItem("Body")
Call mailBody.AppendRTItem(rtitem)
Call mailDoc.Send(False)
End Sub
这里最大的问题是您要从哪里获取要发送的富文本字段?在原始代码中,您尝试从新创建的文档(我称之为mailDoc的文档)中读取它。但这没有任何意义。 您的问题只是您没有从任何地方阅读富文本。
如果您的目标是发送电子邮件,则可以使用我的邮件通知类:
http://blog.texasswede.com/updated-mailnotification-class-now-with-html-email-support-and-web-links/
然后你的代码看起来像这样:
Dim session As New NotesSession
Dim mail As NotesMail
' *** Create a mail
Set mail = New NotesMail()
' Set receipient and subject
mail.MailTo = session.CommonUsername
mail.Subject = "Employee Information"
mail.Principal = "noreply@example.com"
' Create body content from rtitem.
' Yes, I should have added a method in the
' class to append RichtText to the mail body...
mail.body.AppendRTItem(rtitem)
Call mail.Send()
你唯一要做的就是从某个地方获取rtitem。由于您的原始代码声明了一个NotesUIWorkSpace对象和一个NotesUIDocument对象,我猜您想从当前打开的文档中读取它。然后,您只需将以下内容添加到代码的开头:
Dim ws As New NotesUIWorkspace
Dim thisdoc As NotesDocument
Dim rtitem as NotesRichTextItem
Set thisdoc = ws.CurrentDocument.Document
Set rtitem = thisdoc.GetFirstItem("Body")
您是否也看到使用描述性变量名时读取的容易程度?
答案 1 :(得分:0)
您好,您没有保存文件。请注意,如果未保存文档,则Richtext不可用。