Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array used in loop gets error 1

Status
Not open for further replies.

EchoAlertcom

IS-IT--Management
Oct 8, 2002
239
0
0
US
Hello,

I have a script that isn't working and need a little guidance.

It is taking a sting that looks like:
Code:
email@address.com, email2@address.com, email3@address.com

and splitting the string into an array then looping sending mail using CDONTS. I have posted the page below.

The line that is identified as producing the error is line
19.
varMail.To = MyArray(I)

Code:
<html>
<head></head>
   <body>            
      <%
         Dim myString, myArray, I, varMail

         MyString = Request.Form(&quot;fldEmailList&quot;)
         MyArray = split(MyString,&quot;,&quot;)
					

         Set varMail = Server.CreateObject(&quot;CDONTS.Newmail&quot;) 

         varMail.From = &quot;sfunk@cfl.rr.com&quot; 						
         varMail.Subject = &quot;Test 123&quot;
         varMail.Body = &quot;test 23456&quot;
					
         For I=0 to Ubound(MyArray)
	
            varMail.To = MyArray(I)
            varMail.Send 

         Next
					
         Set varMail = Nothing
      %>
   </body>
</html>

Please help me with what is going wrong.

Sincerely.
Steve
 
hey Steve,

That code looks good but CDonts apparently can't handle that.

I tweaked it like this:
Code:
For I=0 to Ubound(MyArray)
Set varMail = Server.CreateObject(&quot;CDONTS.Newmail&quot;) 
varMail.From = &quot;sfunk@cfl.rr.com&quot;                         
varMail.Subject = &quot;Test 123&quot;
varMail.Body = &quot;test 23456&quot; 
varMail.To = MyArray(I)
varMail.Send 
Set varMail = Nothing
Next

that works. I don't know exactly what it is that CDONTS doesn't like. Maybe someone else could shed some light on that. I just know it doesn't work the other way.

If you are sending too many emails that could be a pretty slow script, but it will work.

I hope it works for you.


Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 

Hi Steve,

Your code seems to be alright. But may be the comp you are working on doesn't have CDONTS installed on it.

Try using CDO instead..CDO is installed with various flavors of Outlook and Exchange server... CDONTS is installed with IIS (specifically, the SMTP component).

You have to change your code a lil'

set varMail=Server.CreateObject(&quot;CDO.Message&quot;)
and
varMail.TextBody=&quot;whatever&quot;

Hope this helps...
Sweta
 
Thank you both for your answers.

tlhawkins's fixed it. It would appear that CDONTS can't be used in a loop unless it is destroyed and re-opened. Like it can only send one message at a time.

Thanks again.

Steve
 
Hey steve,

thanks for the star. [bigsmile]

One last note on this:

you can send multiple emails with CDONTS if you concatentate the emails with a semicolon.

like:
varMail.To = &quot;e1@mail.com;e2@mail.com;e3@mail.com&quot;

i'm not positive if the recipients can all see each others email addresses though. You could test that.

if it worked out you could just replace &quot;,&quot; for &quot;;&quot; in your email list and send it once to the whole list.

just something to look into that might lower the load on the server.




Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
Great suggestion for mailing to employees which is one of the two implementations. This one is for clients, where we will need to not expose our client list. I will probably do it the way you just suggest for employees sending email to other employees.

Cheers,
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top