凭借我非常有限的知识,我拼凑了以下代码,以使用 CDOSys 发送和电子邮件发送到我的数据库中找到的每条记录,这些记录有一个电子邮件地址。
电子邮件发送正常,但页面返回错误:
CDO.Message.1 错误“8004020c”
至少需要一个收件人,但没有找到。
cdo-sys2.asp,第 42 行
第 42 行是 = objMessage.Send
从我读到的内容来看,这与循环有关,最终找不到带有电子邮件地址的记录,一篇帖子说需要 0 而不是 1,但我的知识太有限,无法弄清楚从这里去哪里。
非常感谢任何可以帮助我完成这个项目的人。
<%
Set OBJdbConnection = CreateObject("ADODB.Connection")
OBJdbConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("vfeast4fgrav4q3vfg3a34v12.mdb")
SQLQuery = "SELECT FirstName, Email_Address FROM AddressTable"
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
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") ="test@mail.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"" <test@mail.mydomain.com>"
objMessage.To = Rcpt
objMessage.HTMLBody = body
objMessage.Send
End Sub
set objMessage = Nothing
set cdoConfig = Nothing
%>