Send email to 2 Domino groups

Have a problem to send an email to 2 groups using Lotusscript. Here is the code for only one group, but I need to add second group to sendTo

Set view = db.getview(“Groups”)

Set doc = view.getdocumentbykey(“Calendar Group”)

memo.SendTo =doc.getfirstitem(“Members”)

Thanks for your help

Subject: send email to 2 Domino groups

This is a good example of why you should sometimes write more verbose code, and thereby making it more flexible and easier to upgrade in the future.

I would solve it as follows:

Dim sendto As String

Dim group As Variant ’ Will be an array later

Set view = db.GetView(“Groups”)

'*** Get the first group and put into array

Set doc = view.GetDocumentByKey(“Calendar Group”)

group = doc.GetItemValue(“Members”)

'*** Build string of mail addresses, separated by comma

ForAll g in group

sendto = sendto + g + “,”

End ForAll

'*** Get the second group and put into array

Set doc = view.GetDocumentByKey(“Calendar Group2”)

group = doc.GetItemValue(“Members”)

'*** Add new addresses to string of mail addresses

ForAll g in group

sendto = sendto + g + “,”

End ForAll

Call memo.ReplaceItemValue(“SendTo”, Split(sendto))

Don’t use extended notation (e.g. memo.SendTo), use the full class methods.

I would also recommend taking a look at my mail notication class, it makes it very easy to add multiple recipients to an email.

http://blog.texasswede.com/lotusscript-mail-notification-class/

Your code woould them look like this:

Dim group As Variant ’ Will be an array later

Set view = db.GetView(“Groups”)

Set mail = New NotesMail()

'*** Get the first group and put into array

Set doc = view.GetDocumentByKey(“Calendar Group”)

group = doc.GetItemValue(“Members”)

'*** Build string of mail addresses, separated by comma

ForAll g in group

Call mail.AddMailTo(g)

End ForAll

'*** Get the second group and put into array

Set doc = view.GetDocumentByKey(“Calendar Group2”)

group = doc.GetItemValue(“Members”)

'*** Add new addresses to string of mail addresses

ForAll g in group

Call mail.AddMailTo(g)

End ForAll

Call mail.Subject = “Your Subject”

Call mail.Send()

Subject: Simpler solution

Unless you want to do something like log the individual names, it’s not necessary to write a loop to process the members of each group. The appendToTextList method handles this very nicely.

dim sendToItem as NotesItem

dim group1MembersArray as variant

dim group2MembersArray as variant

set sendToItem = memo.getFirstItem(“SendTo”)

Set view = db.getview(“Groups”)

’ get array of members of first group

Set doc = view.getdocumentbykey(“Calendar Group”)

group1MembersArray = doc.getItemValue(“Members”)

’ get array of members of second group

set doc = view.getDocumentByKey(“The Second Group”)

group2MembersArray = doc.getItemValue(“Members”)

’ append each array to the SendTo item

call sendToItem.appendToTextList(group1MembersArray)

call sendToItem.appendToTextList(group2MembersArray)

Subject: RE: Simpler solution

You are right, that is simpler. I just did not think about that, since I rarely use that method…