How do I code ASP to limit ASPMail to only send 50 emails at a time?

I am using ASP (not asp.net) and have the ASPMail component installed on the hosting provider.  I have an app I am writing that will send out a notification email to members of an online group each time a message is posted to the group.  Because of limitations by the host, I need to be able to send only 50 emails at a time.  The emails are stored in a MSSQL database.

Any help would be appreciated as to some simple code to achieve this.  Thanks!
jwingardAsked:
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.

NorushCommented:
You kan keep track of the number of email you have send using a Application Variable.

if Application("intNumberOfMailsSend") = "" then
    Application("intNumberOfMailsSend") = 1
else
    Application("intNumberOfMailsSend") = Clng(Application("intNumberOfMailsSend")) + 1
end if
 
if Clng(Application("intNumberOfMailsSend")) < 50 then
    'Code to send the emails
end if

Open in new window

0
mwhitworthCommented:
Instead of sending one big email, make a loop based on an array of the email addresses and send each email individually.
0
jwingardAuthor Commented:
I wanted to share the code that I am using.  Maybe this will help.  What I'd like to do is have the BCC field have 50 people at a time in it and no more than 50.

The code I've provided is my attempt to get it to cycle through 50 at a time, but it just does not work - instead it sends 10 emails to 50 people.  :-(

NoRush:  I am not familiar with the Application variable.  Would I just place the code as is - wouldn't I have to configure ASPMail to send one a a time with your method and not put 50 at a time in the BCC field?  I'd prefer to send 50 at a time using BCC instead of 50 individual emails - tends to be much slower.

Thanks for your help.  I'm about to pull my hair out over all of this.
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
    Mailer.ContentType = "text/html"
	Mailer.FromName = "Riverland Hills Baptist Church Groups"
	Mailer.FromAddress = "rhgroups@riverlandhills.org"
	Mailer.RemoteHost = "scriptmail.intermedia.net"
    Mailer.AddRecipient "Groups", "rhgroups@riverlandhills.org"
 
do while not rs5.EOF
 
	 for i = 1 to 20
 
          if rs5.EOF then
               Exit For
          end if
 
	Mailer.AddBCC rs5("Name"), rs5("Email")
 
    	rs5.MoveNext
 next
 
 
	Mailer.Subject = "A New Message Has Been Posted in Your RHBC Group!"
	Mailer.BodyText = "<table width=500 border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=top><font face = Lucida Grande,Tahoma,Arial><p><strong>Riverland Hills Baptist Church Group Update</strong></p><p>This message is to let you know that an update has been made to the <strong>" & rs3("Name") & "</strong> group on the Riverland Hills groups web site.<br><br>A new posting entitled <strong>" & Request("Title") & "</strong> has been added to your group by " & Request("Author") & ".<BR><BR><BR><a href = http://www.riverlandhills.org/groups/group.asp?GID=" & Session("GID") & ">Click here to visit your group page.</a>**</p><p>&nbsp;</p></font><p><font face=arial size=1>This information is automatically sent by the group system as a courtesy to you to alert you of a new posting.  It is recommended that you add the email address you received this messsage from (rhgroups@riverlandhills.org) to your address book to prevent this message from being blocked by your spam filter.<br><br><br> **If you are unable to click on the link above please go to http://groups.riverlandhills.org and select your group to view the updated message.</font></p></td></tr></table>"
	

Open in new window

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

mwhitworthCommented:
Thats not the full code.  Can you include the part where it sends the email as well?  Again, I can easily switch that to send seperate emails.  Its better to send many than one with lots of BCC.  For one, you can even put their name in the email and their own email address in the email field.  Second, under many state and Federal laws you have to include remove information and have their email listed in the TO field else you could be hit with violation of spam laws.

But that being said, you just need to move your loop from where you currently have it to the part where it sends and have it send a few emails to everyone.


Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
    Mailer.ContentType = "text/html"
        Mailer.FromName = "Riverland Hills Baptist Church Groups"
        Mailer.FromAddress = "rhgroups@riverlandhills.org"
        Mailer.RemoteHost = "scriptmail.intermedia.net"
    Mailer.AddRecipient "Groups", "rhgroups@riverlandhills.org"
 
do while not rs5.EOF
 
         for i = 1 to 20
 
          if rs5.EOF then
               Exit For
          end if
 
        Mailer.AddBCC rs5("Name"), rs5("Email")
 
        rs5.MoveNext
 next
 
 
        Mailer.Subject = "A New Message Has Been Posted in Your RHBC Group!"
        Mailer.BodyText = "blah blah"

Open in new window

0
NorushCommented:
Forget what i said about Application variables.

Instead change your logic to this attached code
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.ContentType = "text/html"
Mailer.FromName = "Riverland Hills Baptist Church Groups"
Mailer.FromAddress = "rhgroups@riverlandhills.org"
Mailer.RemoteHost = "scriptmail.intermedia.net"
Mailer.AddRecipient "Groups", "rhgroups@riverlandhills.org"
    
Dim lngCounter
lngCounter = 1
	
do while not rs5.EOF
	if lngCounter <= 50 then
		Mailer.AddBCC rs5("Name"), rs5("Email")
	end if
		
	lngCounter = lngCounter + 1
		
	rs5.MoveNext
wend 
	
Mailer.Subject = "A New Message Has Been Posted in Your RHBC Group!"
Mailer.BodyText = "<table width=500 border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=top><font face = Lucida Grande,Tahoma,Arial><p><strong>Riverland Hills Baptist Church Group Update</strong></p><p>This message is to let you know that an update has been made to the <strong>" & rs3("Name") & "</strong> group on the Riverland Hills groups web site.<br><br>A new posting entitled <strong>" & Request("Title") & "</strong> has been added to your group by " & Request("Author") & ".<BR><BR><BR><a href = http://www.riverlandhills.org/groups/group.asp?GID=" & Session("GID") & ">Click here to visit your group page.</a>**</p><p>&nbsp;</p></font><p><font face=arial size=1>This information is automatically sent by the group system as a courtesy to you to alert you of a new posting.  It is recommended that you add the email address you received this messsage from (rhgroups@riverlandhills.org) to your address book to prevent this message from being blocked by your spam filter.<br><br><br> **If you are unable to click on the link above please go to http://groups.riverlandhills.org and select your group to view the updated message.</font></p></td></tr></table>"

Open in new window

0
jwingardAuthor Commented:
Reviewing this code it looks like it would send an email to the first 50 people in the database and then that's it.  How do I get it to create an email with 50 BCC's then cycle back to the remaining batches of 50 people at a time.  Make sense?  (Or maybe I am not making any sense. )
0
NorushCommented:
So y ou want to send 1 single which contains 50 bcc entry's  ?
0
jwingardAuthor Commented:
Yes, one email at a time with 50 bcc;s and cycle through the database as many times necessary to send another email with 50 more until end of database.
0
NorushCommented:
Try with this code.

Dim objConn
Dim rs5
Dim lngCounter
Dim lngNumberOfEmailAddresses
Dim lngNumberOfMailsToSend
Dim lngRemainer
Dim lngRecord
Dim i, j, k
	
lngNumberOfEmailAddresses = rs5.RecordCount
lngNumberOfMailsToSend = int(lngNumberOfEmailAddresses / 50)
	
lngRemainer = lngNumberOfEmailAddresses mod 50
	
if (lngNumberOfEmailAddresses mod 50) > 0 then
	lngNumberOfMailsToSend = lngNumberOfMailsToSend + 1
end if
 
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.ContentType = "text/html"
Mailer.FromName = "Riverland Hills Baptist Church Groups"
Mailer.FromAddress = "rhgroups@riverlandhills.org"
Mailer.RemoteHost = "scriptmail.intermedia.net"
Mailer.AddRecipient "Groups", "rhgroups@riverlandhills.org"
	
For i = 1 To lngNumberOfMailsToSend
	lngRecord = ((i-1) * 50)
		
	Response.Write "Email = " & i & "<BR>"
	For j = 1 to lngRecord
		rs5.MoveNext
	Next
		
	if i < lngNumberOfMailsToSend then
		for k = 1 to 50
			Mailer.AddBCC rs5("Name"), rs5("Email")
			rs5.MoveNext
		next
	else
		for k = 1 to lngRemainer
			Mailer.AddBCC rs5("Name"), rs5("Email")
			rs5.MoveNext
		next
	end if
		
	rs5.MoveFirst
		
	Mailer.Subject = "A New Message Has Been Posted in Your RHBC Group!"
	Mailer.BodyText = "<table width=500 border=0 cellspacing=0 cellpadding=0><tr><td align=center valign=top><font face = Lucida Grande,Tahoma,Arial><p><strong>Riverland Hills Baptist Church Group Update</strong></p><p>This message is to let you know that an update has been made to the <strong>" & rs3("Name") & "</strong> group on the Riverland Hills groups web site.<br><br>A new posting entitled <strong>" & Request("Title") & "</strong> has been added to your group by " & Request("Author") & ".<BR><BR><BR><a href = http://www.riverlandhills.org/groups/group.asp?GID=" & Session("GID") & ">Click here to visit your group page.</a>**</p><p>&nbsp;</p></font><p><font face=arial size=1>This information is automatically sent by the group system as a courtesy to you to alert you of a new posting.  It is recommended that you add the email address you received this messsage from (rhgroups@riverlandhills.org) to your address book to prevent this message from being blocked by your spam filter.<br><br><br> **If you are unable to click on the link above please go to http://groups.riverlandhills.org and select your group to view the updated message.</font></p></td></tr></table>"
	Mailer.Send
Next

Open in new window

0
jwingardAuthor Commented:
Unfortunately that didn't work.  I used your code exactly as provided and all I get is a blank screen - doesn't seem to process anything.
0
NorushCommented:
I dont write anything to the screen in my code.  Arent the mails send either?

And what is the exact syntax for the send method of the SMTPsvg.Mailer object ?

If you run the page again and do a view source of the html does it show any errors ?
0
jwingardAuthor Commented:
I found the code below on another post on ExpertsExchange that seems to be what I am looking for.  However, in looking at the code, it appears that on the last run of a batch of 10 emails, if there aren't exactly 10 emails left in the database then the function would not run and those people would not be sent an email.  I've tested this on our server and that is exactly what is happening.  Any thoughts?
'Send only 50 at a time
counter = 0
 
do while not rs5.eof
 
  if counter = 10 then
    counter = 0	
    	If Mailer.SendMail then
	REsponse.Write("SENT TO 20 PEOPLE!")
		End If
  end if
 
  Mailer.AddBCC rs5("Name"), rs5("Email")
  Response.Write("Email: " & rs5("Email") & "<BR>")
 
  counter = counter + 1
	 rs5.movenext
loop

Open in new window

0
jwingardAuthor Commented:
Found the answer on another web site...
0

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
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.