Home > Archive > dBASE Web Applications > December 2005 > loop problem in sending emails according to filter set









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author loop problem in sending emails according to filter set
Melih

2005-12-08, 7:23 am

Hi,what I need to do is sending emails to all the customers who clicked to
receive news from my website.
So I made a filter which is seen below.
These customers would receive the index .html page as an html email.

The code below belongs to David Ball and it works perfect except the lines
that I have added which is "do while true" loop to send emails to the
filtered customers.
And the problem is it just sends 1 email to the 1st customer of the filter
set.
Not to the others.So the loop is wrong and I have tried to write the loop
codes to different parts of the code but couldn't make it work.It always
sends the html mail to the 1st customer.
Any help is greatly appreciated.
Thx
Melih

d = new Database() // Instantiate database object
d.databaseName = 'WEBSAMPLE'
d.active = true

email2 = new query() //("select Email from Recipients")
email2.database = d
email2.sql= 'select firstname, email from :websample:customers
where
news="true" or news="on"'
email2.active=true

* get the HTML page from the server by FTP
if file('c:\windows\get
Page2.log') // erase any previous log
erase 'c:\windows\getPage2
.log'
endif
if file('c:\windows\get
Page.bat') // see below to create this file
run c:\windows\getPage.bat
* you could put some error checking in here for run return codes
else
oCGI.sorryPage("c:\windows\getPage.bat not found")
return
endif

* prepare email
smtp = new email()
* do while not email2.rowset.endOfSet
* smtp. addAddress(trim(emai
l2.rowset.fields["email"].value))
* email2.rowset.next()
smtp.isHTML = true
smtp.body=''

* convert the downloaded file contents to the message body
sdf = new file()
sdf.open( "c:\temp\index.html","R")
do while not sdf.eof()
xcv=sdf.gets()
smtp.body = smtp.body + xcv
enddo

smtp.timeout = 10000
smtp.FromName = "Mentesoglu Kagitcilik Tic ve San A.S."
smtp.Subject = "Yenilik haberi"

* send email
if smtp.send()
* display success message
oCGI.streamHeader("Mail successfully sent")
with oCGI.fOut
puts("<body><h1>Mail successfully sent</h1><h3>FTP log</h3>")
dfg = new file()
dfg.open( "c:\winnt\getPage.log","R")
do while not dfg.eof()
** WARNING!! shows FTP password on browser
oCGI.fOut.puts(dfg.gets()+ chr(10)+chr(13))
enddo
endwith
else
oCGI.sorryPage("Mail could not be sent", "Problem")
return
endif
enddo

catch(exception e)
oCGI.errorPage(e.message)
endtry

oCGI = null

return

class email of oleautoclient("persits.mailsender") custom // do not change
this.host:="mail.lfchosting.com" // put your ISP's Mail Server name
this.from := "admin@mentesoglu.com" // put your e-mail address
endclass


David Ball

2005-12-08, 8:23 pm

Hi Melih

> * prepare email
> smtp = new email()
> do while not email2.rowset.endOfSet
> smtp. addAddress(trim(emai
l2.rowset.fields["email"].value))
> email2.rowset.next()



//The do while loop should end right about here. It is only required to add
multiple recipients.
enddo
// Don't forget to remove your original enddo below

....
....
....
> else
> oCGI.sorryPage("Mail could not be sent", "Problem")
> return
> endif




// REMOVE THIS ENDDO

>* enddo



Thank you
David Ball
www.ChelseaData.ca


Melih

2005-12-09, 7:23 am

> > * prepare email[color=darkred]

enddo

Hi David;
this doesn't work. No emails is sent with the code above.

the below code has some results:

* prepare email
smtp = new email()
do while not email2.rowset.endOfSet
//email2.rowset.next() ---if i add this line , then no emails is sent
smtp.isHTML = true
smtp.body=''
// email2.rowset.next() -- no emails

* convert the downloaded file contents to the message body
sdf = new file()
sdf.open( "c:\temp\index.html","R")
do while not sdf.eof()
xcv=sdf.gets()
if "<img"$xcv
nLoc=at('src="',xcv)+5
if nLoc>5 //
xcv=stuff(xcv,nLoc,0
,'http://www.mentesoglu.com/' )
endif
endif
smtp.body = smtp.body + xcv
enddo
// email2.rowset.next() -- no emails

smtp.timeout = 10000
smtp.FromName = "Mentesoglu Kagitcilik Tic ve San A.S."
smtp.Subject = "Yenilik haberi"
// email2.rowset.next() -- no emails

smtp.addbcc(trim(email2.rowset.fields["email"].value))
email2.rowset.next() -- send email to only to the 1st customer
email2.rowset.next()
enddo

* send email
if smtp.send()
//email2.rowset.next() -- sends the same email to the 1st customer for
2 TIMES
* display success message
oCGI.streamHeader("Mail successfully sent")
with oCGI.fOut
puts("<body><h1>Mail successfully sent</h1><h3>FTP log</h3>")
dfg = new file()
dfg.open( "c:\windows\getPage2.log","R")
do while not dfg.eof()
** WARNING!! shows FTP password on browser
oCGI.fOut.puts(dfg.gets()+ chr(10)+chr(13))
enddo
endwith
smtp.reset()
else
oCGI.sorryPage("Mail could not be sent", "Problem")
return
endif
enddo // if I remove this "enddo" from here , no emails is sent.


David Ball

2005-12-09, 8:23 pm

Melih

> Hi David;
> this doesn't work. No emails is sent with the code above.


That's unfortunate. It worked correctly for me. Approximately how many
customers is this email going to? Maybe there is an upper limit in your
email client or aspemail.

Please see below this code block.

> do while not email2.rowset.endOfSet
> //email2.rowset.next() ---if i add this line , then no emails is sent
> smtp.isHTML = true
> smtp.body=''
> // email2.rowset.next() -- no emails
> * convert the downloaded file contents to the message body
> sdf = new file()
> sdf.open( "c:\temp\index.html","R")
> do while not sdf.eof()
> xcv=sdf.gets()
> if "<img"$xcv
> nLoc=at('src="',xcv)+5
> if nLoc>5 //
> xcv=stuff(xcv,nLoc,0
,'http://www.mentesoglu.com/' )
> endif
> endif
> smtp.body = smtp.body + xcv
> enddo
> // email2.rowset.next() -- no emails
>
> smtp.timeout = 10000
> smtp.FromName = "Mentesoglu Kagitcilik Tic ve San A.S."
> smtp.Subject = "Yenilik haberi"
> // email2.rowset.next() -- no emails
>
> smtp.addbcc(trim(email2.rowset.fields["email"].value))
> email2.rowset.next() -- send email to only to the 1st customer
> email2.rowset.next()
> enddo


This is the complete loop that you have built - each of these commands will
be run for each eligible customer. Is that what you want to do? I don't
think so.

A "do while" loop runs each command until it reaches enddo, then goes to the
top and does it all over again as long as the while condition remains true.
The rowset.next() command moves to the next customer at the end of each
loop. ( FIX: You have 2 next() commands at the end of the loop so currently
you are sending email to only half of the recipients.)
If you have 100 customers, you will be doing all of this 100 times. The
ONLY thing that should be done 100 times is the addbcc() and the
rowset.next(). The email text does not need to be parsed and stuffed 100
times.

Thank you
David Ball
www.ChelseaData.ca


Melih

2005-12-09, 8:23 pm

David,
I'm using lfchosting as a server so there are no upper limits.And also my
original code has only one next() command at the end of the loop...so
everything seems ok.

But it doesn't work.The problem should be sth else but what?

Melih

"David Ball" <Thanks.But@NoSpam.4.me> wrote in message
news:ccN4IqR$FHA.1232@news-server...
> Melih
>
>
> That's unfortunate. It worked correctly for me. Approximately how many
> customers is this email going to? Maybe there is an upper limit in your
> email client or aspemail.
>
> Please see below this code block.
>
>
> This is the complete loop that you have built - each of these commands
> will
> be run for each eligible customer. Is that what you want to do? I don't
> think so.
>
> A "do while" loop runs each command until it reaches enddo, then goes to
> the
> top and does it all over again as long as the while condition remains
> true.
> The rowset.next() command moves to the next customer at the end of each
> loop. ( FIX: You have 2 next() commands at the end of the loop so
> currently
> you are sending email to only half of the recipients.)
> If you have 100 customers, you will be doing all of this 100 times. The
> ONLY thing that should be done 100 times is the addbcc() and the
> rowset.next(). The email text does not need to be parsed and stuffed 100
> times.
>
> Thank you
> David Ball
> www.ChelseaData.ca
>
>



David Ball

2005-12-09, 8:23 pm

> David,
> I'm using lfchosting as a server so there are no upper limits.


ASPEmail client activex may have a limit on how many email addresses that
you can send to per email. I imagine the server has a per-email limit as
well.

> And also my
> original code has only one next() command at the end of the loop...so
> everything seems ok.


That's good, but I can only see what you put in the posting.

> But it doesn't work.The problem should be sth else but what?


Melih, I have provided you with code that works properly for me, and I have
tried to assist you with understanding it and getting it to run for you. I
have no more ideas at this time - if you post your code, I will debug it the
same way as I have done before. Perhaps someone else can assist you.

Are there any error messages?
How many recipients are you trying to send to?
Have you tried stepping through the debugger to see what is happening?

Thank you
David Ball
www.ChelseaData.ca


Melih

2005-12-12, 7:23 am

It's working now,thx again David.
Melih


David Ball

2005-12-13, 8:23 pm

That's good news! Thanks for letting us know.

Dave

"Melih" <vedat@turk.net> wrote...
> It's working now,thx again David.
> Melih
>
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com