LotusScript agent to send mail to multiple recipients from csv file

Viewed 119

I need LotusScript agent action button to send email to multiple recipients which mail addresses will be read from csv or excel file. I have to send identical mail to couple hundred recipients and it's much easier to send it from excel file than to type or copy each one individually. I've found "Send" method on HCL site and implementation with Static Array example:

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 

This action button should send email to 3 recipients or as many as I manually enter in code but is there a way to send send email to recipients from csv or excel file?

1 Answers

Yes, of course, there is a way.

To read from a CSV file, you can use the NotesStream class to read the data from the file. Or you can use the Open statement and the old BASIC-like file operations to read data from the file. Either way, of course, you're going to be writing a CSV file parser. You might find some examples of that if you search for them, but really it's not that hard.

To read from an Excel sheet in LotusScript, you're going to need to call the Excel API classes. Here's one example that I found: link. I'm sure that there are plenty of others. Many people would do this the other way, though, by writing VBA code that runs in Excel and calls the Lotus classes. A search here on StackOverflow for "send Lotus Notes email from Excel VBA" will definitely bring up some examples. One could also write VBScript code that runs standalone and uses both the Excel classes and the Notes classes, and you can undoubtedly find some examples of that, too.

Related