Tuesday, 6 November 2018

Domino 10 - Programatically Schedule Mail Using LotusScript


In my previous blog post Domino 10 - New Administrator Feature to Push to Notes Clients: Scheduled Messages I described the new Domino 10 feature scheduled delivery of mail messages. As mentioned in the blog post the new Domino 10 Mail Servers supports scheduled delivery of mail messages. For example a user can compose a new mail message during the weekend and schedule the delivery of the email to be sent during the next work week. Scheduled messages are stored in mail.box on the sender's Mail Server. The router delivers or routes the messages at the scheduled time. Scheduled mail is enabled on a Domino 10 Server by default. In the Server Configuration Settings document in the Domino directory it can be disabled by the Administrator.
Scheduled messages are supported for Notes client users with mail files that are upgraded to he Notes 10 Mail Template (mail10.ntf). The feature is not supported for IBM iNotes, IBM Verse or IBM Traveler clients.
In this blog post I will describe how you can programatically schedule mail using LotusScript.


Scheduling mail programatically
To programatically schedule mail messages you must use the Summary DateTime item $SendAt to cause a message to be scheduled. Below a basic example using a simple function which is called form an Action Button on a Notes form.

A. Function ScheduledMail
In the Funtion ScheduledMail I use a Variant sendTime which indicates when the mail should be sent. The value of the Variant sendTime in the Function ScheduledMail is replaced in the field $SendAt to cause the message to be scheduled on the Domino Server.

Function ScheduledMail(note As NotesDocument)
Dim session As New NotesSession
Dim db As NotesDatabase
Dim memo As NotesDocument
Dim body As NotesRichTextItem
Dim sendTime As Variant
Dim linkDoc As NotesDocument
Dim sendTo As String
Set db = session.CurrentDatabase
Set memo = db.CreateDocument
Call memo.ReplaceItemValue("Form", "Memo")
Call memo.ReplaceItemValue("Subject", "Review IT Ticket Solution")
sendTo = note.mailuser(0)
sendTime = Today + 8 + TimeNumber(8, 0, 0)
Call memo.ReplaceItemValue("$SendAt", sendTime)
Call memo.ReplaceItemValue("SendTo", sendTo)
Set body = memo.CreateRichTextItem("Body")
Call body.Appendtext("Please review this IT Ticket: ")
Call body.Appenddoclink(linkDoc, "", "")
body.Update
Call memo.Send(False)
End Function

B. Mail.Box
If the user selects the Action Button on the Notes Form the function ScheduledMail is called and the mail is not send immediately but is placed in the Mail.Box on the Server as a Pending Message.


By using sendTime = Today + 8 + TimeNumber(8, 0, 0) in the Function ScheduledMail the Scheduled Time for the Mail Message is set on 14-11-2018 08:00:00.


The above function can be easily adjusted so that the users can enter the scheduled date and time themselves. Another great new feature in Domino 10. In my next blog post more about scheduling messages using @Formula.

No comments:

Post a Comment