代码之家  ›  专栏  ›  技术社区  ›  Apinya Chabaram

LotusScript获取富文本字段并发送电子邮件

  •  0
  • Apinya Chabaram  · 技术社区  · 7 年前

    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
    
    2 回复  |  直到 7 年前
        1
  •  0
  •   Karl-Henry Martinsson    7 年前

    我注意到的一件事是,您没有在正在创建的邮件文档上设置表单。

    我还建议您使用更好的变量名,在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")
    

        2
  •  0
  •   Robert Kreutzer    7 年前

    您好,您没有保存文档。请注意,如果未保存文档,Richtext不可用。