使用CDO发送电子邮件,同时遍历电子邮件的数据库记录集

时间:2019-05-03 18:55:25

标签: loops asp-classic recordset cdo

我有一个经典的ASP记录集,该记录集可以使用CDONTS拉,循环和发送电子邮件。我遇到的问题是,随着记录集遍历代码,用户会收到他们自己的电子邮件以及其他人的电子邮件。

我没有尝试解决此问题,但是我想知道是否有一种在迭代过程中暂停循环以确保每次发送一封电子邮件的方法。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
<meta http-equiv="Refresh" content="5;url=young_eagles_volunteers.asp?YEEventID=<% REQUEST("YEEventID") %>">
<title>Young Eagles Confirm Participation</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>

<body class="body">
<%
sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"



Set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendUrl)=2
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
objConfig.Fields.Update



Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration=objConfig
objMail.From="ye@eaa309.club"
objMail.ReplyTo=""

DIM conn, sql, str_YEEventID
str_YEEventID	= REQUEST("YEEventID")


		SET conn = SERVER.CREATEOBJECT("ADODB.Connection")
		conn.OPEN eaa309
		set rsYEReminder=Server.CreateObject("ADODB.recordset")

	    sql=("EXEC [dbo].[sp_select] @yeEventID = "&str_YEEventID&"")
			rsYEReminder.Open sql,conn



IF NOT rsYEReminder.EOF AND NOT rsYEReminder.BOF THEN

  DO WHILE NOT rsYEReminder.EOF

  HTML = HTML & "<HTML>"
  HTML = HTML & "<HEAD>"
  HTML = HTML & "<TITLE>Reminder</TITLE>"
  HTML = HTML & "<link href='/main.css' rel='stylesheet' type='text/css' />"
  HTML = HTML & "</HEAD>"
  HTML = HTML & "<BODY>"
  HTML = HTML & "<img alt='EAA' src='images/YEPart_Reminder.png' border='0'><br><br>"
  HTML = HTML & "<span class='bodysmall'><b>ATTENTION:</b> Volunteer("& rsYEReminder("Full Name") &" - "& rsYEReminder("YEE_VOLUNTEER_TYPE") & ") Please respond by clicking either the Yes or No buttons below if you are still planning on participating in the upcoming Young Eagles Event at "& rsYEReminder("YE_Event_Location_Name") & "</span><br><br>"

  HTML = HTML & "<a href=''><img alt='EAA' src='images/yes_button.png' border='0'></a><br><br>"& vbCrlf
  HTML = HTML & "<a href=''><img alt='EAA' src='images/no_button.png' border='0'></a><br><br>"& vbCrlf

	IF rsYEReminder("YP Status") = "Expired" THEN
	HTML = HTML & "<span class='note'>NOTE: It appears that your Youth Protection Certification has expired. Prior to the event please log into your EAA account by clicking on this link: <a href='accountlogin' target='_blank'></a> Then click My Account and then Training Information - Go to training. When you have completed your training please send an email to the current YE coordinator or chapter secretary. Thank you!</span><br><br>"
	ELSEIF rsYEReminder("Status") = "Not Taken" THEN
	HTML = HTML & "<span class='note'>NOTE: It appears that you've not taken the EAA Youth Protection Certification training course. Prior to the event please log into your EAA account by clicking on this link: <a href='accountlogin' target='_blank'></a> Then click My Account and then Training Information - Go to training. When you have completed your training please send an email to the current YE coordinator or chapter secretary. Thank you!</span><br><br>"
	END IF


  HTML = HTML & "<hr>"
  HTML = HTML & "</BODY>"
  HTML = HTML & "</HTML>"


  objMail.To=rsYEReminder("Email")
	objMail.Bcc="kbnetguy@gmail.com"
  objMail.Subject="EAA CHapter Young Eagle Reminder"
  objMail.HTMLBody=HTML
  objMail.Send

  rsYEReminder.MOVENEXT
  LOOP
END IF



%>

</body>
</html>

每个人只能发送一封单独​​的自定义电子邮件。根据记录集,任何用户都不应收到多于一封针对其他用户的电子邮件。

1 个答案:

答案 0 :(得分:0)

您需要在两次迭代之间重置objMail对象。我认为每次循环执行objMail.To时,您只需将下一个emailaddress添加到邮件中,然后再次发送。

尝试将这些行移动到循环中:

Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration=objConfig
objMail.From="ye@eaa309.club"
objMail.ReplyTo=""

,然后作为循环的最后一行:

set objMail=nothing