Reputation: 31
I am pretty close to being able to forward documents from lotus notes. I have an almost working script but am missing something. I see some notes on setting MailOptions or SaveOptions but I can not get it to work for what I think is a NotesUIDocument. I get either
or
by removing or adding the Call uiForward.Save. The NotesUIDocument does not seem to take arguments and I don't see how to modify any of the options in a UIdocument. What incantation will tell notes to just close or discard the forwarded UIdocument?
I simplified the script to remove the loop. It will just send the first note in the test folder.
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim session As New NotesSession
Dim sendTo As String
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim uiDoc As NotesUIDocument
Dim uiForward As NotesUIDocument
' address to send emails to
sendTo$ = "[email protected]"
' get current database
Set db = session.CurrentDatabase
' Get list of documents in test folder
Set view = db.GetView("Test")
' get first document
Set doc = view.GetFirstDocument
' Open the email for read only in the Notes UI
Set uiDoc = ws.EditDocument(False, doc)
' Forward the email, creating a new document in the UI
uiDoc.Forward
' Get the new document to be forwarded
Set uiForward = ws.CurrentDocument
' Enter To email address(es) (comma-separated)
uiForward.GoToField "To"
uiForward.InsertText sendTo
' close original document, not needed at this point
uiDoc.Close(True)
' Send and close the forwarded document - the email is put in the Sent folder
uiForward.Send
' Save the forwarded document
' This prevents the save dialog but then gets a different discard, send only, save only, cancel, save & send dialing
Call uiForward.Save
' Close the forwarded note
uiForward.Close(True)
End Sub
Upvotes: 0
Views: 537
Reputation: 2359
Did you know that there's a standard option in the Address Book for forwarding all incoming mails to some address?
A NotesUIDocument is a foreground object, but you don't really have to use these objects. I gather that you're trying to "forward" specific mails to some destination address. May I suggest the following approach (LotusScript sort-of):
Set doc= view.GetFirstDocument
Set newdoc= doc.CopyToDatabase(doc.ParentDatabase)
Call newdoc.ReplaceItemValue("SendTo", "[email protected]")
Call newdoc.Send(False)
Call newdoc.Save(True, False) ' if you want to save the document
Update, 2nd option
This will create a new mail, and add the content of the original mail. I have no idea if the new mail will resemble the original mail. Furthermore, check thoroughly if attachments are copied...
Set doc= view.GetFirstDocument
Set newdoc= New NotesDocument(doc.ParentDatabase)
Call newdoc.ReplaceItemValue("SendTo", "[email protected]")
Dim body As New NotesRichTextItem(newdoc, "Body")
' you could add lines to body here, like
' Call body.AppendText("Mailed: " + Format$(doc.PostedDate(0))
' Call body.AddNewline(1)
Call body.AppendRTItem(doc.GetFirstItem("Body"))
Call newdoc.Send(False)
Call newdoc.Save(True, False) ' if you want to save the document
See the LotusScript documentation: https://help.hcltechsw.com/dom_designer/9.0.1/appdev/LSAZ_CHAPTER_2CREATING_COMPILING_AND_DEBUGGING_SCRIPTS.html
Upvotes: 2