精华区 [关闭][返回]

当前位置:月光软件>>讨论区精华>>〖软件开发〗>>● ASP>>★ASP的应用★>>ASP环境下邮件列表功能的实现 (四)

主题:ASP环境下邮件列表功能的实现 (四)
发信人: cousin()
整理人: netyum(2002-07-23 19:01:36), 站内信件
 
     最后要实现的功能是邮件的编辑和发送。这部分功能由Email_List.asp文件
提供,其界面如图6所示。接下来我们就来分析这个文件。 

   Email_List.asp的内部工作过程和edit_record.asp很类似。管理员在表单
中写作邮件并提交它,系统将选择所有Mail_List字段值为“是”的记录,然后将
新邮件的拷贝发送给这些记录中的Guest_Mail地址。 

   每一次发送邮件我们都重新创建mailer对象,发送完成后关闭它。这一点非
常重要,这是由于我们需要修改邮件的正文,加入取消订阅邮件列表的URL和ID号
。 

 if Request.ServerVariables("REQUEST_METHOD") = "POST" then
  strSubject = Request.Form("txtSubject")
  strBody = Request.Form("txtBody")
  strFrom = Request.Form("txtFrom")
  ' 从数据库选取收件人记录
  strSQL_SelectEmail = "SELECT Guests.Guest_ID, Guests.Guest_Email " 
& _
  " FROM Guests WHERE ((Guests.Mail_List)=-1);" 
  Set oConn = Server.CreateObject("ADODB.Connection")
  oConn.Open strDSNPath
  Set rsMail = oConn.Execute(strSQL_SelectEmail)
  if rsMail.BOF = True and rsMail.EOF = True then
  ...数据库为空提示,略...
  else
  rsMail.MoveFirst
  Do While Not rsMail.EOF
  ' 创建对象
  Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
  ' 填写其它邮件标题信息
  Mailer.FromName = strFrom
  Mailer.FromAddress = strEmailFrom
  Mailer.RemoteHost = strHost
  Mailer.Subject = strSubject
  Mailer.BodyText = ...设置邮件内容,略...
  strTo = rsMail.Fields("Guest_Email").Value
  If strTo < > "" then
  Mailer.Recipient = strTo
  if Mailer.SendMail then
  ...发送成功提示,略...
  else
  ...发送失败提示,略...
  end if 'Mailer.SendMail
  end if 'strTo < > ""
  rsMail.MoveNext
  Set Mailer = Nothing
  Loop
  end if 'rsMail.BOF = True and rsMail.EOF = True
  rsMail.Close
  Set rsMail = Nothing
  oConn.Close
  Set oConn = Nothing
 end if 'REQUEST_METHOD = "POST"

   这里需要注意的是,我们将变量strHost的值赋给ASPMail的实例对象的Rem
oteHost属性。因此,必须保证strHost的值是一个合适的邮件服务器名字(如ma
il.mydomain.com)。  

--
※ 来源:.月光程序代码网 http://www.moon-soft.com.[FROM: 202.104.133.66]

[关闭][返回]






转载请注明:转载自 月光程序代码网 [ http://www.moon-soft.com ]