I have a routine that is supposed to grab all email addresses within a certain group. The email address list can be well over 1000 emails. When emailing it out though I can only send around 150 emails at a time. So what I i've done is executed a query and threw all the emails into a collection.

How do I now reiterate through the collection grab 100 addresses each time and call the routine to email that group?

Dim emailToGroup As String = ddlEmailTo.SelectedValue

        Dim connStr As String = ConfigurationManager.ConnectionStrings("SNA_TRT").ConnectionString
        Dim sqlConn As SqlConnection
        sqlConn = New SqlConnection(connStr)

        Dim strSQLgetEmails As String = "SELECT C.contact_email as Company FROM cust_emerg_contacts E INNER JOIN TRT_parent_accounts A ON E.CompID = A.CompID INNER JOIN MRT_customer_contacts C ON E.ContactID = C.id WHERE (A.CARE_LEVEL LIKE '" & emailToGroup & "') AND (A.[Status] = 'Active')"

        Dim cmd As New SqlCommand(strSQLgetEmails, sqlConn)
        Dim dr As SqlDataReader = cmd.ExecuteReader()

        Dim EmailCol As New Collection
        Dim count As Integer = 0
        While dr.Read
            EmailCol.Add(count, dr(0))
            count &= 1
        End While



        'Grab 100 emails stuff into a string  (toEmailList) and send the message. Grab Next 100 and send message.. ect. ect
        'SendMail(tbEmailFrom.Text, ToEmailList, tbEmailSubject, tbMessageBody)

I THINK I have it worked out!

'Loop through Collection in groups of Step Value
        For step100 = 1 To EmailCol.Count Step 5
            'set the starting value of the smaller set value
            Dim step1 As Integer = step100
            'create the email string
            Dim EmailToString As String = String.Empty
            'set the amount of small loop to default value
            Dim totSmallLoop As Integer = 4

            'check and make sure small loop does not go past the total collect count
            'if it does set count to collection amount - current row
            If step1 + totSmallLoop > EmailCol.Count Then
                totSmallLoop = EmailCol.Count - step1
            End If

            'loop through the subset 
            For step1 = step100 To step100 + totSmallLoop Step 1
                EmailToString &= EmailCol.Item(step1) & ";"
            'SendMail(tbEmailFrom.Text, ToEmailList, tbEmailSubject, tbMessageBody)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.