以下代码用于从数据库中提取名字和电子邮件,并通过CDOSys和电子邮件发送到找到的记录。
我的托管服务将收件人数量限制为10,所以我认为将查找限制在前10条记录,然后发送然后查找接下来的10条记录并发送等等是不可能的,直到到达表的末尾?
<%
Set OBJdbConnection = CreateObject("ADODB.Connection")
OBJdbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("myData.mdb")
SQLQuery = "SELECT FirstName, Email_Address FROM MyTable"
Set Result = OBJdbConnection.Execute(SQLQuery)
if Not Result.EOF then
Do While Not Result.EOF
SendMail Result("FirstName"), Result("Email_Address")
Result.MoveNext
Loop
end if
OBJdbConnection.Close()
Set OBJdbConnection = Nothing
Sub SendMail(TheName, TheAddress)
Dim objMessage, Rcpt
If (TheName <> "" AND TheAddress <> "") Then
smtpServer = "mail.mydomain.com"
body = "Hello World"
Rcpt = Chr(34) & TheName & Chr(34) & "<" & TheAddress & ">"
set objMessage = Server.CreateObject("CDO.Message")
set cdoConfig = Server.CreateObject("CDO.Configuration")
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
cdoConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
cdoConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="smtp@mydomain.com"
cdoConfig.Fields ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="123456"
cdoConfig.Fields.Update
set objMessage.Configuration = cdoConfig
objMessage.Subject = "This Month's Sales"
objMessage.From = """Acme Sales"" <me@mydomain.com>"
objMessage.To = Rcpt
objMessage.HTMLBody = body
objMessage.Send
End If
End Sub
set objMessage = Nothing
set cdoConfig = Nothing
%>
答案 0 :(得分:0)
我认为这可能是你想要做的。
<%
if Not Result.EOF then
i = 0
Do While i<10
SendMail Result("FirstName"), Result("Email_Address")
Result.MoveNext
i= i+1
Loop
....
%>