我想我已经很接近了,但它还没有。我正在生成一个记录集,然后分配变量并使用这些变量构建电子邮件,发送电子邮件,然后移动到下一条记录并再次执行,直到它们全部完成。我的问题是,在我的示例代码中,它确实发送了四 (4) 封电子邮件,但它们都是第一条记录,因此它不会移动到下一条记录。这是我的示例代码:
set rs_remailer = Server.CreateObject("ADODB.recordset")
sql="SELECT contact.ID, contact.contacttypeID, contact.firstname, contact.lastname, contact.email, contact.company, contact.phone, contact.street, contact.location, contact.cityID, contact.postal, contact.comments, contact.email_alert, contact.created_date, cities.ID AS citiesID, cities.countryID, cities.displayname AS citiesdisplayname, contacttype.displayname AS contacttypedisplayname FROM contact INNER JOIN cities ON cities.ID = contact.cityID INNER JOIN contacttype ON contacttype.ID = contact.contacttypeID WHERE (contact.ID BETWEEN 5753 AND 5757) ORDER BY contact.ID ASC;"
rs_remailer.Open sql, conn
remailerTotalRecords = rs_remailer.getRows()
Dim contact_ID()
Dim contact_createddate()
Dim contact_contacttypedisplayname()
Dim contact_firstname()
Dim contact_lastname()
Dim contact_email()
Dim contact_company()
Dim contact_phone()
Dim contact_street()
Dim contact_location()
Dim contact_postal()
Dim contact_comments()
Dim contact_emailalert()
Dim contact_citiesdisplayname()
contactNumber = 0
while not rs_remailer.eof
ReDim Preserve contact_ID(contactNumber+1)
ReDim Preserve contact_createddate(contactNumber+1)
ReDim Preserve contact_contacttypedisplayname(contactNumber+1)
ReDim Preserve contact_firstname(contactNumber+1)
ReDim Preserve contact_lastname(contactNumber+1)
ReDim Preserve contact_email(contactNumber+1)
ReDim Preserve contact_company(contactNumber+1)
ReDim Preserve contact_phone(contactNumber+1)
ReDim Preserve contact_street(contactNumber+1)
ReDim Preserve contact_location(contactNumber+1)
ReDim Preserve contact_postal(contactNumber+1)
ReDim Preserve contact_comments(contactNumber+1)
ReDim Preserve contact_emailalert(contactNumber+1)
ReDim Preserve contact_citiesdisplayname(contactNumber+1)
contact_ID(contactNumber) = rs_remailer("ID")
contact_createddate(contactNumber) = FormatDateTime(rs_remailer("created_date"),1)
contact_contacttypedisplayname(contactNumber) = rs_remailer("contacttypedisplayname")
contact_firstname(contactNumber) = rs_remailer("firstname")
contact_lastname(contactNumber) = rs_remailer("lastname")
contact_email(contactNumber) = rs_remailer("email")
contact_company(contactNumber) = rs_remailer("company")
contact_phone(contactNumber) = formatphone(rs_remailer("phone"))
contact_street(contactNumber) = rs_remailer("street")
contact_location(contactNumber) = rs_remailer("location")
contact_postal(contactNumber) = rs_remailer("postal")
contact_comments(contactNumber) = rs_remailer("comments")
contact_emailalert(contactNumber) = rs_remailer("email_alert")
contact_citiesdisplayname(contactNumber) = rs_remailer("citiesdisplayname")
emailcontent = ""
emailcontent = emailcontent & "<h2>" & contact_contacttypedisplayname(i) & " Form Submission</h2>"
emailcontent = emailcontent & "<p>This message was originally sent on: " & contact_createddate(i) & " </p>"
emailcontent = emailcontent & "<p>The following Form Submission was made on the ADS-Pipe website:</p>"
emailcontent = emailcontent & "<table border='0' cellspacing='0' cellpadding='2'>"
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>User:</b></td>"
emailcontent = emailcontent & "<td width='6' align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'>" & contact_firstname(i) & " " & contact_lastname(i) & "</td>"
emailcontent = emailcontent & "</tr>"
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>E-mail:</b></td>"
emailcontent = emailcontent & "<td width='6' align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'><a href='mailto:" & contact_email(i) & "'>" & contact_email(i) & "</a></td>"
emailcontent = emailcontent & "</tr>"
if not isblank(contact_company(i)) then
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>Company:</b></td>"
emailcontent = emailcontent & "<td width='6' align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'>" & contact_company(i) & "</td>"
emailcontent = emailcontent & "</tr>"
end if
if not isblank(contact_phone(i)) then
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>Phone:</b></td>"
emailcontent = emailcontent & "<td width='6' align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'>" & contact_phone(i) & "</td>"
emailcontent = emailcontent & "</tr>"
end if
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>Address:</b></td>"
emailcontent = emailcontent & "<td width='6' align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'>"
if NOT isblank(contact_street(i)) then emailcontent = emailcontent & contact_street(i) & "<br />"
if NOT isblank(contact_location(i)) then emailcontent = emailcontent & contact_location(i) & "<br />"
if NOT isblank(contact_postal(i)) then emailcontent = emailcontent & contact_postal(i)
emailcontent = emailcontent & "</td>"
emailcontent = emailcontent & "</tr>"
if NOT isblank(contact_comments(i)) then
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>Comments:</b></td>"
emailcontent = emailcontent & "<td width='6' align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'>" & contact_comments(i) & "</td>"
emailcontent = emailcontent & "</tr>"
end if
if contact_emailalert(i) then
emailcontent = emailcontent & "<tr>"
emailcontent = emailcontent & "<td align='right' valign='top' nowrap='nowrap'><b>E-mail Alerts:</b></td>"
emailcontent = emailcontent & "<td align='left' valign='top'> </td>"
emailcontent = emailcontent & "<td align='left' valign='top'>The customer has indicated that they would like to receive e-mail updates about ADS technical information and products.</td>"
emailcontent = emailcontent & "</tr>"
end if
emailcontent = emailcontent & "</table>"
emailcontent = emailcontent & "<br />"
'---------------------------------------------------------------------------
'CLOSE THE DATABASE
'rs_contactFormDisplayname.close
'---------------------------------------------------------------------------
'send email notification
dim Mailer
set Mailer = server.createobject("CDO.Message")
location_parts = Split(contact_location(i), ",")
suffix = " "
if UBound(location_parts) = 2 then suffix = " (" & trim(location_parts(2)) & ")"
email_subject = "[Website] " & contact_contacttypedisplayname(i) & " Form Submission" & suffix
Mailer.From = ""
Mailer.HtmlBody = "<html><body>" & emailcontent & "</body></html>"
Mailer.Subject = email_subject
with Mailer.Configuration
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailserver
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Fields.Update
end with
Mailer.Send
set Mailer = Nothing
CDOSYS_Mailer = true
contactNumber = contactNumber + 1
rs_remailer.movenext
wend
remailerTotalRecords = rs_remailer.RecordCount
rs_remailer.close
response.end
我想我只是没有找到让记录向上移动的地方,所以下一个被使用。