以下代码用于从数据库中提取名字和电子邮件,并通过 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
%>