Using LotusScript, you can generate and send email messages. When creating the email message, recipient email addresses must be assigned to the SendTo field. To send an email to a single recipient, simply set the object value to a valid email address. For example:
doc.SendTo = "someone@ibm.com"
However, when sending email to multiple recipients, you must create an array of values and append the values to the SendTo, CopyTo, or BlindCopyTo field(s). This can be achieved by building either a static or dynamic array of values.
Note
You must create an array of values in order to assign values to the SendTo field. Assigning a comma-delimited string of email addressessuch as "JohnDoe@company.com, JaneDoe@company.com"will be interpreted as a string email value and will produce an error when the email is sent.
How It Works
Create an array of email addresses and assign the array to the SendTo, CopyTo, or BlindCopyTo field(s). This can be accomplished through a static array (where addresses are hard-coded in the code) or dynamic array (where values are parsed from a view or other Lotus Notes object). Both implementation options are described in the following.
ImplementationStatic Array Example
The following illustrates how to implement the static array approach. In this example, three values are assigned the SendTo field. To implement this solution, insert this code in an action button. Replace "EMAIL" with valid email addresses (such as "myname@company.com"). When clicked, the email will be sent to all recipients.
Sub Click(Source As Button) Dim s As NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim rtitem as NotesRichTextItem Set s = New NotesSession Set db = s.CurrentDatabase Set doc = New NotesDocument(db) '---------------------------------------------------------------------- ' Build static list of email addresses '---------------------------------------------------------------------- Dim addresses (1 to 3) as String addresses(1) = "EMAIL" addresses(2) = "EMAIL" addresses(3) = "EMAIL" '---------------------------------------------------------------------- ' Create and send email message '---------------------------------------------------------------------- doc.Form = "Memo" doc.SendTo = addresses doc.Subject = "This is the message subject" Set rtitem = New NotesRichTextItem(doc, "Body") Call rtitem.AddNewLine(1) Call rtitem.AppendText("The body of the email message.") doc.Send (True) Msgbox "Sample email sent" End Sub
ImplementationDynamic Array Example
The following illustrates how to implement the dynamic array approach. In this example, the array of email addresses is dynamically built by looping through all documents in a particular view. The array is created based on a specific document field for each document in the view. This approach could be used where users create a profile or email subscription for the database. The subscription view is then used to build the array of email recipients. To implement this solution, insert this code in an action button. Replace FIELD and VIEW with valid database design elements.
Sub Click(Source As Button) Dim s As NotesSession Dim db As NotesDatabase Dim doc As NotesDocument Dim rtitem As NotesRichTextItem Dim i As Integer Set db = s.CurrentDatabase Dim view As NotesView Set view = db.GetView("VIEW") '---------------------------------------------------------------------- ' Build dynamic list of email addresses '---------------------------------------------------------------------- i=0 Set doc = view.GetFirstDocument While Not(doc Is Nothing) Redim Preserve addresses(i) addresses(i) = doc.FIELD(0) i = i + 1 Set doc = view.GetNextDocument(doc) Wend '---------------------------------------------------------------------- ' Create and send email message '---------------------------------------------------------------------- Set doc = New NotesDocument(db) doc.Form = "Memo" doc.SendTo = addresses doc.Subject = "This is the message title" Set rtitem = New NotesRichTextItem(doc, "Body") Call rtitem.AddNewLine(1) Call rtitem.AppendText("The body of the email message.") doc.Send (True) Msgbox "Sample email sent" End Sub
An Introduction to the Lotus Domino Tool Suite
Getting Started with Designer
Navigating the Domino Designer Workspace
Domino Design Elements
An Introduction to Formula Language
An Introduction to LotusScript
Fundamentals of a Notes Application
Calendar Applications
Collaborative Applications
Reference Library Applications
Workflow Applications
Web Applications
Design Enhancements Using LotusScript
Design Enhancements Using Formula Language
View Enhancements
Sample Agents
Miscellaneous Enhancements and Tips for Domino Databases
Data Management
Security
Application Deployment and Maintenance
Troubleshooting
Appendix A. Online Project Files and Sample Applications
Appendix B. IBM® Lotus® Notes® and Domino®Whats Next?