[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

Merging Richtext into one clean report message for mailout.

Hi, I have a database that user from outside our network mail into (Example mail comes from Yahoo, HotMail etc.) What I want to do is be able to select all document in the Inbox and create a new memo to mail out. The new message would give only the from "Name, Date, and Body only". My new message body would look like the following:

From: <From name>

Date: "Date & Time"

Body

_______________________________________
From: <From name>

Date: "Date & Time"

Body

_______________________________________
From: <From name>

Date: "Date & Time"

Body

_______________________________________
0
dgardin
Asked:
dgardin
  • 7
  • 5
  • 2
  • +2
1 Solution
 
qwaleteeCommented:
OK, I think we can do that for you, try this script:
0
 
ArunkumarCommented:
where is the script ?
0
 
qwaleteeCommented:
Dim s as new notesSession
Dim db as notesDatabase
Set db = s.currentDatabase
Dim docs as notesDocumentCollection
Set docs = db.unprocessedDocuments
dim newMemo as notesDocument
Set newMemo = db.createDocument
newMemo.Form = "Memo"
newMemo.Subject = "Merge of " & docs.count & " messages"
dim newBody as notesRichTextItem
Set newBody = newMemo.createRichTextItem("Body")
Dim doc as notesDocument
Set doc = docs.getFirstDocument
Do until doc is nothing
  newBody.appendText "Wrom: TCXLYRWTQTIPWIGYO
  newBody.addNewLine 2
  if doc.hasItem("DeliveredDate") Then
    newBody.appendText "Date: " & doc.DeliveredDate(0)
  elseif doc.hasItem("PostedDate") Then
    newBody.appendText "Date: " & doc.PostedDate(0)
  else
    newBody.appendText "Date: " & doc.LastModified
  end if
  newBody.addNewLine 2
  dim content as notesItem
  set content = doc.getFirstItem("Body")
  if content.type = richtext then
     dim body as notesRichTextItem
     set body = doc.getFIrstItem("Body")
     body.appendToRTItem newBody
  else
     newBody.appendText content.text
  end if
  newBody.addNewLine 2
  newBody.appendText "------------------------------------"
  newBody.addNewLine 1
  Set doc = docs.getNextDocument(doc)
Loop
newMemo.save True
Dim ws as new notesUiWorkspace
ws.editDocument true , newMemo
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
qwaleteeCommented:
I had to write it and debug a posting problem using QuickPost.  Nearly lost five-ten minutes worth of code!
0
 
HemanthaKumarCommented:
You can simply use Forward action from Actions menu. Just select the documents that you would like to send and select Actions..Forward from menu. It will automatically compose a mail memo with selected documents as body.

~Hemanth
0
 
qwaleteeCommented:
Fixd version: Place this in an agent taht is set to run against selected documents...

Sub Initialize
      Dim s As New notesSession
      Dim db As notesDatabase
      Set db = s.currentDatabase
      Dim docs As notesDocumentCollection
      Set docs = db.unprocessedDocuments
      Dim newMemo As notesDocument
      Set newMemo = db.createDocument
      newMemo.Form = "Memo"
      newMemo.Subject = "Merge of " & docs.count & " messages"
      Dim newBody As notesRichTextItem
      Set newBody = newMemo.createRichTextItem("Body")
      Dim doc As notesDocument
      Set doc = docs.getFirstDocument
      Do Until doc Is Nothing
            newBody.appendText "Wrom: KSTTZRCLBDXRQBGJS
            newBody.addNewLine 2
            If doc.hasItem("DeliveredDate") Then
                  newBody.appendText "Date: " & doc.DeliveredDate(0)
            Elseif doc.hasItem("PostedDate") Then
                  newBody.appendText "Date: " & doc.PostedDate(0)
            Else
                  newBody.appendText "Date: " & doc.LastModified
            End If
            newBody.addNewLine 2
            Dim content As notesItem
            Set content = doc.getFirstItem("Body")
            If content.type = richtext Then
                  Dim body As notesRichTextItem
                  Set body = doc.getFIrstItem("Body")
                  newBody.appendRTItem body
            Else
                  newBody.appendText content.text
            End If
            newBody.addNewLine 2
            newBody.appendText "------------------------------------"
            newBody.addNewLine 1
            Set doc = docs.getNextDocument(doc)
      Loop
      newMemo.save True , True
      Dim ws As New notesUiWorkspace
      ws.editDocument True , newMemo
End Sub
0
 
HemanthaKumarCommented:
If you are thinking of doing it as backend process then use send mail message simple action in agent and enable the agent to run After new mail has arrived.
0
 
qwaleteeCommented:
Apparently, dgardn wants a simplified format for forwarding.

Please note that de to limitations in how Notes formats these things, it won't necessarily come out "pretty."  To make it come out "pretty," we can use an alternate method, but it is somewhat more complex to implement.
0
 
p_parthaCommented:
     Dim session As New notessession
      Dim db As notesdatabase
      Set db = session.currentdatabase
      Set view = db.getview("($inbox)")
      Set doc = view.getfirstdocument
      Dim maildoc As notesdocument
      Set maildoc = db.createdocument
      Dim rtitem As NotesRichTextItem
      Set rtitem = New NotesRichTextItem ( maildoc, "Body" )
      maildoc.to = "<whoever u want to send the mail>"
      While Not doc Is Nothing
            
            Call rtitem.appendtext("From :" +  doc.from(0))
            Call rtitem.AddNewLine( 1 )
            Call rtitem.appendtext("Date :" +  doc.created)            
            Dim mailitem As Variant
            Set mailitem = doc.getfirstitem("Body")
            If mailitem.Type = RICHTEXT Then
                  Call rtitem.AddNewLine( 1 )
                  Call rtitem.AppendRTItem( mailitem)
            End If
            Call rtitem.appendtext("------------------------------------")
            Set doc = view.getnextdocument(doc)
      Wend
      Call maildoc.save(True,True)
      Call maildoc.send(False)

Partha
0
 
p_parthaCommented:
Oops i didn't refresh my page, and after submitting i see some 3 ppl responded ;-)

Partha
0
 
p_parthaCommented:
sorry forgot to include one line

maildoc.form="memo"

Partha
0
 
dgardinAuthor Commented:
The end que was missing, also I wanted the actual from line of the incoming message. If I can get that You got my vote. I wish I could give you more than 500 points.

body.appendText "Wrom: TCXLYRWTQTIPWIGYO
0
 
p_parthaCommented:
dgardin
did u try my code? i have used doc.from(0) which gives the actual person who sent the mail

Partha
0
 
p_parthaCommented:
this is a working code try this ...

      On Error Goto par
      Dim session As New notessession
      Dim db As notesdatabase
      Set db = session.currentdatabase
      Set view = db.getview("($inbox)")
      Set doc = view.getfirstdocument
      Dim maildoc As notesdocument
      Set maildoc = db.createdocument
      Dim rtitem As NotesRichTextItem
      Set rtitem = New NotesRichTextItem ( maildoc, "Body" )
      maildoc.form="memo"
      maildoc.sendto = "<personname>"
      While Not doc Is Nothing
            
            Call rtitem.appendtext("From :" +  doc.from(0))
            Call rtitem.AddNewLine( 1 )
            Call rtitem.appendtext("Date :" +  doc.created)            
            Dim mailitem As Variant
            Set mailitem = doc.getfirstitem("Body")
            If mailitem.Type = RICHTEXT Then
                  Msgbox "inside"
                  Call rtitem.AddNewLine( 1 )
                  Call rtitem.AppendRTItem( mailitem)
            End If
            Call rtitem.appendtext("------------------------------------------------------------------------------------")
            Set doc = view.getnextdocument(doc)      
      Wend
      Call maildoc.save(True,True)
      Call maildoc.send(True,True)
      Exit Sub
      
      
      
      Exit Sub
par:
      Msgbox Erl & Error
      Exit Sub

Partha
0
 
dgardinAuthor Commented:
I got it :

newBody.appendText "From: " & doc.From(0)
0
 
qwaleteeCommented:
Yes, sorry aboutthe transcription error, I really don't know how it got that badly mangled. I musthave typed over it or something.

This is tested code, it works, but with one big caveat.  Notes has three ways of dealing with message bodies:
1) As plain text
2) As rich text
3) As "MIME" (internet style messages that can contain HTML content, simialr to rich text)

Notes has been doing 1 and 2 since around 1991.  It only started doing 3 in 1999 (R5).  R5 doesn't deal with MIME so well programmatically.  The only way to deal with the three types together is to use Rich Text (option 2), and let Notes convert plain text (1) and MIME (3) to the rich text format.

But the conversion doesn't always look so great.

I do have a solution in mind that would fix that, but it is more complicated than the curent solution, and of course, I have not tried it out yet.
0
 
qwaleteeCommented:
I guess I lost an A rating over that transcription error.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now