Agent (and special view) needed to send out mails


i need an agent sending out a mail to everyone who appears in my inbox.

i need a new view, similar to the inbox folder, showing incomming mails.
i don't want to see duplicate sender addresses. so something like "unique" on from / replyto ...or what ever is good to use here.

then i need an agent  going from the first mail until to the last mail and create per incomming mail a new mail (regarding the subject: not a real reply).
the agent should do this:
- so imagine looking at your inbox.
- sort it e.g. by date. go to the 1st mail.
- do a reply
- change the subject to "this my special mail"
- put some predefined text (not person specific) into the body
- press send-only
- goto the next mail...and so on
- ....and all this in the special unique view

if this  works it would look like this:
- i open a new view or folder
- i see all mails beeing sent to me sofar from all senders
- if a sender writes 3 mails to me, i only see 1 of them
- i press "agent xxx run"
- the agent will create some thousand mails with a spcific subject and body.

anything unclear?
please respond

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sjef BosmanGroupware ConsultantCommented:
You don't need an agent for this. Why don't you put all your addresses into the BCC at once, so they won't see each other's mail address? It's just one mail then. All addresses you can get by making a copy of the ($Inbox) folder and adding a column filled with From, and then using
   @DbColumn("":""; ""; "Your $Inbox"; new_column_number)
Sjef BosmanGroupware ConsultantCommented:
Forgot the @Unique:
   @Unique(@DbColumn("":""; ""; "Your $Inbox"; new_column_number))
hreinartAuthor Commented:
thanks for the quick reply.

there is a barrierer sending out 1 mail to thousands of receipients.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Sjef BosmanGroupware ConsultantCommented:
There's even a better approach maybe (with an agent...). In the mail-database (R6) there is an action Add Recipients\to new Group in Address Book. You could copy this agent and modify it to Add Originators\to new Group in Address Book. Inside the Declaration section there is a function ProcessCandidates(), with 4 times almost identical lines (SendTo, CopyTo, etc). You could modify this one to read
   If Me.m_noteCandidate.hasitem("From") And Len(Me.m_noteCandidate.GetItemValue("From")(0)) Then
      Me.m_strRecipientArray = Arrayappend(Me.m_strRecipientArray,AppendDomain(Me.m_noteCandidate.GetItemValue("SendTo")))  
                  End If

Maybe there are even more things to change, but you could test this with only a few mails selected. If you have created the group in your N&A-book, you can put this group into the BCC of your mail.

Good luck!
Are you talking about sending a message to every person who has ever sent you a message?  Or only to those that are currently in your inbox (those that you have not deleted and not moved to a different folder)?
hreinartAuthor Commented:

i'm using r5, sorry didn't mention it.
i'm looking for a complete solution, i can't program

i'm laszy .... ;-)
nearly all people who wrote me a mail are (still) in my inbox.
so this would work, if you have something running on this (or duplicate) view.
Sjef BosmanGroupware ConsultantCommented:
R5? I don't know if I still have that template... same Action is there, probably also the same coding. But if you cannot program, do you have the Notes Designer or what? How do you plan to do the necessary coding?

I tested it for you, and it works just as I described above. Your recipe:
1. View the Design of your mail database
2. go to the Agents
3. make a copy of Add Recipients\to new Group in Address Book
4. name this one Add Senders\...
5. go to Declarations
6. look for the function ProcessCandidates
7. look for the 2 lines with SendTo
8. replace all words SendTo by From
9. throw away 6 lines starting with If Me.m_noteCandidate.hasitem("CopyTo")
10. save, close, goto Notes, Actions, and click your new Action

You then create a new group in your N&A-book.
hreinartAuthor Commented:

i have a desinger.
if i do all what you tested, what can i do with the new group in my n&a?

ok, i can't do it, but is it really so complicate to write an agent doing:
- go to the 1st document in the view or folder
- create a reply
- change subject to:  xxxx
- change body to:   yyyy
- send the mail without saving locally


Sjef BosmanGroupware ConsultantCommented:
Okay, you added the agent, did you activate it? It asked you to type the name of a group, and after the OK it created this group for you in you personal N&A Book. Is that right, is there a new group?

If so, you can just write one new mail, name the group in the BCC and press send. That should be all. If you think you have too many names in the group, split it up into several groups and send more mails.

Whether writing an agent is complicated depends on the person you're asking it from. It takes quite some time, which I haven't go (or don't want to spend for free). Helping you is no problem, but I'm not going to lead you all the way. Be a sport, do try it for yourself...
hreinartAuthor Commented:

i wonder why you always reply to the questions and write: i don't have time for it.
if you don't have time, please don't reply.
i need a solution, that's why i ask here...and normally get the needed answers.

splitting up in  groups is not what i want.
i don't want to count until (about) 250 recipients and go for the next 250...

i need that solution that creates one mail after the other (or 1 mail with 249 bcc receipients).

nichts für ungut, aber alles andere bringt mir nichts......
Sjef BosmanGroupware ConsultantCommented:
' Agent Add Senders\to new Group in Address Book

Use "Common"
Option Declare

Class AddToGroupStringTable
      Function GetString(nIndex As Integer, vData As Variant) As String
            Select Case nIndex
            Case 1
                  GetString = "Rename target group"
            Case 2
                  GetString = "Replace existing group with new group"
            Case 3
                  GetString = "Append selected member(s) to existing group member(s)"
            Case 4
                  GetString = "A group by this name is already defined. "
            Case 5
                  GetString = "Please select the desired action"
            Case 6
                  GetString = "Please enter new group name"
            Case  7
                  GetString = "Lotus Notes"
            Case 8
                  GetString = "-Untitled-"
            Case 9
                  GetString = "Add recipients to new group"
            End Select
      End Function            
End Class

Class GroupHelperLauncher As BaseApplication
      Private m_GroupHelperStringTable As AddToGroupStringTable      
      Private m_uiws As notesuiworkspace
      Private m_dbLocalAddressBook As notesdatabase
      Private m_viewGroup As notesview
      Private m_collection As notesdocumentcollection
      Private m_noteOptions As notesdocument      
      Private m_noteCandidate As notesdocument            
      Private m_noteGroupEntry As notesdocument
      Private m_vUserDomain As Variant
      Private m_vTrimmedList As Variant                        
      Private m_strRecipientArray As Variant
      Private m_nSuccess As Integer            
      Private m_nEntryNumber As Integer            
'//Public Subs and Functions
      Sub Init()
            Set Me.m_GroupHelperStringTable = New AddToGroupStringTable      
            Set Me.m_collection = GroupHelperLauncher..DocumentsToProcess
            If Not Me.m_collection.count > 0 Then
                  Exit Sub
            End If
            Set Me.m_uiws = New notesuiworkspace
            Me.m_vUserDomain = Evaluate(|@Domain|)
            Set Me.m_dbLocalAddressBook = GroupHelperLauncher..LocalAddressBook
            Set Me.m_noteOptions = Me.m_db.CreateDocument
      End Sub
      Function ProcessCandidates()
            Set Me.m_noteCandidate = Me.m_collection.getfirstdocument
            While Not Me.m_noteCandidate Is Nothing
                  If Not Isarray(Me.m_strRecipientArray) Then
                        Redim Me.m_strRecipientArray(0)
                        Me.m_strRecipientArray(0) = ""
                        Me.m_nEntryNumber = Me.m_nEntryNumber + 1                                          
                  End If
                  If Me.m_noteCandidate.hasitem("From") And Len(Me.m_noteCandidate.GetItemValue("From")(0)) Then
                        Me.m_strRecipientArray = Arrayappend(Me.m_strRecipientArray,AppendDomain(Me.m_noteCandidate.GetItemValue("From")))  
                  End If
                  Set Me.m_noteCandidate = Me.m_collection.getnextDocument(Me.m_noteCandidate)            
            Me.m_vTrimmedList = RemoveDuplicates(OptimizeAddressArray(Me.m_strRecipientArray))
            Call Me.m_noteOptions.replaceitemvalue("AllAddresses",Me.m_vTrimmedList)
            Me.m_nSuccess = Me.m_uiws.dialogbox("(GroupHelper)",True,True,False,False,False,False,_
            If Me.m_nSuccess Then
                  Call CreateNABEnrty()            
            End If
      End Function
      Private Function AppendDomain(EmailAddessArray As Variant) As Variant
            If Me.m_noteCandidate.hasitem("FromDomain") Then
                  If Len(Me.m_noteCandidate.GetItemValue("FromDomain")(0)) Then
                        Dim x As Integer
                        For x = 0 To Ubound(EmailAddessArray)
                              If Not EmailAddessArray(x) = "" And Not Isnull(EmailAddessArray(x)) Then
                                    If Not Me.m_vUserDomain(0) = Me.m_noteCandidate.GetItemValue("FromDomain")(0) Then
                                          EmailAddessArray(x) =  EmailAddessArray(x) & "@" & Me.m_noteCandidate.GetItemValue("FromDomain")(0)
                                    End If
                              End If
                  End If
            End If
            AppendDomain = EmailAddessArray
      End Function
      Private Function OptimizeAddressArray(EmailAddress As Variant) As Variant
            On Error Goto TRAP            
            If Isarray(EmailAddress) Then
                  Dim x As Integer
                  Dim vTempName As Variant
                  For x = 0 To Ubound(EmailAddress)
                        If Not EmailAddress(x) = "" Or Not Isnull(EmailAddress(x)) Then
                              vTempName = Evaluate(|@OptimizeMailAddress("| & EmailAddress(x) &|")|)
                              EmailAddress(x) = vTempName(0)
                        End If
                  EmailAddress = Evaluate(|@OptimizeMailAddress("| & EmailAddress &|")|)
            End If
            OptimizeAddressArray = EmailAddress
            Exit Function
            vTempName(0) = EmailAddress(x)
            Resume Next
      End Function
      Function RemoveDuplicates(strArray As Variant) As Variant
            Dim x As Integer            
            Dim y As Integer            
            Dim tmpstrArray() As String            
            Redim tmpstrArray(0)
            For x = 0 To Ubound(strArray)            
                  If Isnull(Arraygetindex(tmpstrArray,strArray(x),1)) Then      
                        tmpstrArray(y) = strArray(x)
                        y = y+1                        
                        Redim Preserve tmpstrArray(y)
                  End If
            RemoveDuplicates = Fulltrim(tmpstrArray)
      End Function
      Function CreateNABEnrty()
            Set Me.m_viewGroup = Me.m_dbLocalAddressBook.GetView("($PeopleGroupsFlat)")            
            Set Me.m_noteGroupEntry = Me.m_viewGroup.Getdocumentbykey(Me.m_noteOptions.GroupName(0),True)
            If Me.m_noteGroupEntry Is Nothing Then
                  '// this is a new group and we'll just populate it
                  Set Me.m_noteGroupEntry = Me.m_dbLocalAddressBook.createdocument
                  With Me.m_noteGroupEntry
                        Call .replaceitemvalue("Form","Group")
                        Call .replaceitemvalue("Type","Group")
                        Call .replaceitemvalue("ListName",Me.m_noteOptions.GetItemValue("GroupName"))
                        Call .replaceitemvalue("GroupType",Me.m_noteOptions.GetItemValue("GroupType"))
                        Call .replaceitemvalue("ListDescription", Me.m_noteOptions.GetItemValue("Description"))
                        Call .replaceitemvalue("Members", Me.m_noteOptions.GetItemValue("SelectedGroupMembers"))
                        Call .save(True,True,True)
                  End With
                  '// this group is already in the NAB, so lets see what they want to do!
                  Dim Options(2) As String
                  Dim strResponse As String
                  Options(0) = Me.m_GroupHelperStringTable.GetString(1,Null)
                  Options(1) = Me.m_GroupHelperStringTable.GetString(2,Null)
                  Options(2) = Me.m_GroupHelperStringTable.GetString(3,Null)
                  strResponse = Me.m_uiws.Prompt(prompt_okcancellist,_
                  Me.m_GroupHelperStringTable.GetString(4,Null) & Chr(13) & _
                  Options(0), Options)
                  Select Case strResponse
                  Case Options(0)
                        'get new group string name from user
                        Dim strtmpGroupString As String
                        strtmpGroupString = Inputbox(Me.m_GroupHelperStringTable.GetString(6,Null),_
                        Call Me.m_noteOptions.replaceitemvalue("GroupName",strtmpGroupString)
                        Call CreateNABEnrty()
                  Case Options(1)
                        'replace the members
                        With Me.m_noteGroupEntry
                              Call .replaceitemvalue("GroupType",Me.m_noteOptions.GetItemValue("GroupType"))
                              Call .replaceitemvalue("Members", Me.m_noteOptions.GetItemValue("SelectedGroupMembers"))
                              Call .save(True,True,True)
                        End With
                  Case Options(2)
                        'append the members to the list (check for unique entries)                              
                        With Me.m_noteGroupEntry
                              Call Me.m_noteOptions.ReplaceItemValue("SelectedGroupMembers",_
                              Call .replaceitemvalue("Members", Me.m_noteOptions.GetItemValue("SelectedGroupMembers"))
                              Call .save(True,True,True)
                        End With
                  End Select
            End If
      End Function
End Class

Sub Initialize
      Dim copyfunction As New GroupHelperLauncher
      Call copyfunction.init()
      Call copyfunction.ProcessCandidates()
End Sub

' Und jetzt genügt's, ich werde nie wieder reagieren auf so eine Frage
hreinartAuthor Commented:
ups.. looks interesting, thanks sofar.

it'd be nice if you could give me some (even short) comments) where to insert this.
will this agent work like i asked?

i'll have to try it out.

hreinartAuthor Commented:


i don't understand what you wrote.
could you please put it in a database and mail it to:

this account will work about 1 pm 11-03-2003

Jean Marie GeeraertsApplication EngineerCommented:
Well, this is actually not all that complicated.
Since you want to send the same mail to everybody in your inbox, all you need to do is first get all the addressees from your inbox, make sure all names in the list are unique and then create the mail for all the addressees.

Here's what to do:
1) Create an agent with the following properties:
- Run 'Manually from agent list'
- Run on 'All Documents in view'
- Use 'LotusScript'
2) Call this agent from your inbox and it will do what you want, no extra view needed. If there are people you don't want included, move them to another folder before running the agent.

The code for the agent :
Sub Initialize
      'Define body text
      Const BODY_TEXT = {Enter any text you want included in your mail here.
You can enter a new paragraph, by just starting the text on a new line here. Just make sure all text is located between the two curly brackets.
      ' initialize variables
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim dc As NotesDocumentCollection
      Dim docIn As NotesDocument
      Dim docOut As NotesDocument
      Dim strAddressees() As String
      Dim varUniqueAddressees As Variant
      Dim i As Integer
      Dim strMacro As String
      Dim rtBody As NotesRichTextItem
      'get reference to database and documents in the current view
      Set db = session.CurrentDatabase
      Set dc = db.UnprocessedDocuments
      If dc.Count = 0 Then
            Messagebox "No documents in view"
            Exit Sub
      End If
      'initialize array to hold all names from the documents in the view
      Redim strAddressees(dc.Count-1)
      'walk through all documents in the view and add the names to the array
      i = 0
      Set docIn = dc.GetFirstDocument
      Do While Not docIn Is Nothing
            strAddressees(i) = docIn.From(0)
            Set docIn = dc.GetNextDocument(docIn)
            i = i + 1
      'store unique names in varUniqueAddressees
      'for this we call @Unique function and pass it the list of all names
      strMacro = {@Unique("} & StrImplode(strAddressees, {":"}) & {")}
      varUniqueAddressees = Evaluate(strMacro)
      'create a new document for all addressees
      Forall a In varUniqueAddressees
            Set docOut = db.CreateDocument
            With docOut
                  .SendTo = a
                  .Subject = "Your fixed subject"
                  Set rtBody = .CreateRichTextItem("Body")
            End With
            Call rtBody.AppendText(BODY_TEXT)
            Call rtBody.AddNewLine(1)
            'Send the document without atttaching the form to the recipient in SendTo field
            Call docOut.Send(False)
      End Forall
End Sub

Function StrImplode(array As Variant, strDelimiter As String) As String
      'This functon is the LS equivalent to @Implode
      'It  takes an array of strings (=array) and combines it to one string, with a fixed delimiter (=strDelimiter)
      Dim i As Integer
      StrImplode = ""
      Dim last As Integer
      last = Ubound(array)
      For i = 0 To (last - 1)
            StrImplode = StrImplode + array(i) + strDelimiter
      StrImplode = StrImplode + array(last)
End Function

If you have any problems implementing the code, just let me know.

Kind Regards,

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.