Forums
This topic is locked
looping content for automated email
Posted 04 Sep 2007 23:14:48
1
has voted
04 Sep 2007 23:14:48 Simon Bloodworth posted:
HiIve been battling away at this on for awhile now and thought i was making progress but it wasnt meant to be.
The idea is that it loops through a recordset which gets user details and from this loops though anoter recordset to search based on info from the first RS. Now the mechanics of the whole work as a response.write shows all the correct sql strings, and if i write them to an acual file it works - but my problem comes from looping through content that makes up the body of the email that gets sent . All the emails send fine based on the users in the db but there is no content so obviously something wrong with my loop but cant see what.
Wondered if anyone else had any ideas - my code follows:
<pre id=code><font face=courier size=2 id=code> <% Dim CurrentDate
CurrentDate = Date()-10
%>
<%
Dim RsUserDetails
Dim RsUserDetails_numRows
Set RsUserDetails = Server.CreateObject("ADODB.Recordset"
RsUserDetails.ActiveConnection = MM_BFJ_STRING
RsUserDetails.Source = "SELECT * FROM tblUpdates"
RsUserDetails.CursorType = 0
RsUserDetails.CursorLocation = 2
RsUserDetails.LockType = 1
RsUserDetails.Open()
RsUserDetails_numRows = 0
Repeat2__index=Repeat2__index+1
Repeat2__numRows=Repeat2__numRows-1
%>
<% While ((Repeat2__NumRows <> 0) AND (Not RsUserDetails.EOF))
Dim RsConstructEmailBody__varDate
RsConstructEmailBody__varDate = "26/08/2007"
If (CurrentDate <> "" Then
RsConstructEmailBody__varDate = CurrentDate
End If
Dim arrSearch, strWhere, strSQL
arrSearch = Split(RsUserDetails.Fields.Item("E_SearchString".value, ","
strWhere = "I_POSTDATE >= #" + Replace(RsConstructEmailBody__varDate, "'", "''" + "#"
For i = 0 To UBound(arrSearch)
strWhere = strWhere & " AND I_CATEGORY LIKE '%" & arrSearch(i) & "%'"
Next
strSQL = "SELECT * FROM tblItemData WHERE " & strWhere
response.Write(strsql & "<BR><BR>"
response.Write(CurrentDate)
Dim RsConstructEmailBody
Dim RsConstructEmailBody_numRows
Set RsConstructEmailBody = Server.CreateObject("ADODB.Recordset"
RsConstructEmailBody.ActiveConnection = MM_BFJ_STRING
RsConstructEmailBody.Source = strSQL
RsConstructEmailBody.CursorType = 0
RsConstructEmailBody.CursorLocation = 2
RsConstructEmailBody.LockType = 1
RsConstructEmailBody.Open()
RsConstructEmailBody_numRows = 0
Set Mailcon = Server.CreateObject("Persits.MailSender"
MailCon.From = " "
MailCon.FromName = "GenoaGoodBoat.com"
Dim EmailAddress
EmailAddress = RsUserDetails.Fields.Item("E_Email".Value
MailCon.AddAddress (EmailAddress)
MailCon.Subject = "Email Update"
do while Not RsConstructEmailBody.EOF
Bodytxt1 = "new listings." & VbCrLf & VbCrLf
Bodytxt1 = Bodytxt1 & "-------------------------------------------------- " & VbCrLf
Bodytxt1 = Bodytxt1 & "Details are: " & VbCrLf
Bodytxt1 = Bodytxt1 & "-------------------------------------------------- " & VbCrLf
Bodytxt1 = Bodytxt1 & "Category : " & RsConstructEmailBody.Fields.Item("I_CATEGORY".Value & VbCrLf
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RsConstructEmailBody.MoveNext()
Loop
Mailcon.Body = Bodytxt1
MailCon.Username = " "
MailCon.Password = "zuxecawi"
MailCon.Host = "smtp.dotnetted.co.uk"
MailCon.Send
Set Mailcon = Nothing
RsUserDetails.MoveNext()
Wend
%>
<%
RsConstructEmailBody.Close()
Set RsConstructEmailBody = Nothing
%>
<%
RsUserDetails.Close()
Set RsUserDetails = Nothing
%></font id=code></pre id=code>
Simon
DWMX 2004 | ASP | VBScript