【问题标题】:Sending emails using CDO while looping through a DB record set of emails在循环通过电子邮件的数据库记录集时使用 CDO 发送电子邮件
【发布时间】:2019-05-03 18:55:24
【问题描述】:

我有一个经典的 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>

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

【问题讨论】:

  • 电子邮件会排队等待发送。 CDONTS 不知道队列中的内容,因此无法暂停。
  • 您需要在循环开始时将 HTML 变量初始化为一个空白字符串。 HTML = ""

标签: loops asp-classic recordset cdo.message


【解决方案1】:

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

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

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

然后在循环的最后一行写:

set objMail=nothing

【讨论】:

    猜你喜欢
    • 2013-10-03
    • 1970-01-01
    • 2016-01-05
    • 1970-01-01
    • 2018-03-18
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多