[thelist] CDO Mail - Looping inside

aardvark roselli at earthlink.net
Fri Nov 3 10:41:12 CST 2000

> From:Edd Partee <edd at vilocity.com>
> I'm trying to send mail using CDO and ASP. My data is coming from a
> database that contains items organized by Order Number. Each order
> number can be associated with more than one item number. I want the mail
> to come out like so:

i'll leave out the part where i bug you for using CDONTS instead of 
many other options (like ASPMail, etc.)...

> strBody = strBody & "Order Number " ... database stuff, line breaks no
> loop
> strBody = strBody & "Customer Name " & ... no loop
> strBody = strBody & "Item Number " & ... I want this one to loop 
> strBody = strBody & "Item details" & ...  also looping
> strBody = strBody & "Order Total" ... no loop 
> I can get everything in place correctly, except the loop for the
> different items. Can I put a loop inside the mail code itself, or do I
> need to loop relevant things into a variable and then pull that in to
> the mail code? I've tried (in my ASP newbie way) a few things, none of
> which worked. Point me in the right direction.

first, write a loop using response.writes... stuff it in a <pre> so it's 
easy to spot on-screen, especially since line breaks may be an 
issue in the email... choose your favorite and most appropriate loop 
(a while loop, a for...next loop, whatever) and make it work there...

then just change your 'response.write's to 'strBody = strBody &'s...

i hope that makes some sense, but ultimately, don't think of it as 
creating an email, think of it as just creating HTML in a <pre>... it 
may be a little easier to grasp, and may make it easier to integrate 
existing code...

in the end, you may have something like (pseudo-code):

strBody = strBody & "foo"
	while ....
		strBody = strBody & var1 & vbcrlf
		strBody = strBody & var2 & vbcrlf
strBody = strBody & "foo2"

More information about the thelist mailing list