通过CDO发送电子邮件,同时通过DB记录集循环



我有一个经典的ASP RecordSet,可以使用ctonts拉,循环和发送电子邮件。我遇到的问题是,随着RecordSet通过代码用户收到自己的个人电子邮件和每个人的其他电子邮件的迭代。

我尚未尝试解决此问题,但是我想知道是否有一种方法可以在迭代时暂停循环以确保一次发送每个电子邮件。

<!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>

只有一封单独的自定义电子邮件应向每个人发放。没有用户应根据记录集的其他用户收到一封以上的电子邮件。

您需要在迭代之间重置objmail对象。我认为每次循环都可以做到objmail.to,您只需将下一个电子邮件address添加到邮件中并再次发送。

尝试将这些线移到循环中:

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

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

set objMail=nothing

最新更新