因为最近工作需要,写了一个使用CDO.Message发送邮件的函数,发上来和大家分享一下。
Sub SendMail(MailServerType,MailAddRecipient,MailSubject,MailBody)
if MailServerType="" or MailAddRecipient=""or MailSubject="" or MailBody="" then
Exit Sub
End if
on error resume next
if MailServerType="JMail" then
Set JMail=Server.CreateObject("JMail.Message")
JMail.Charset="gb2312"
JMail.ContentType = "text/html"
'JMail.ContentType = "text/plain"
JMail.From = "youremail@yourdomain.com"
AddRecipientArray=split(MailAddRecipient,";")
For i=0 to Ubound(AddRecipientArray)
if ""&AddRecipientArray(i)&""<>"" then JMail.AddRecipient AddRecipientArray(i)
Next
JMail.Subject = MailSubject
JMail.Body = MailBody
JMail.MailServerUserName = "SmtpServerUserName"
JMail.MailServerPassword = "SmtpServerPassword"
JMail.Send "SmtpServer"
Set JMail=nothing
elseif MailServerType="CDO" then
Set CDO=Server.CreateObject("CDO.Message")
CDO.From = "youremail@yourdomain.com"
CDO.To = MailAddRecipient
CDO.Subject = MailSubject
CDO.HtmlBody = MailBody
'CDO.TextBody = MailBody
CDO.HTMLBodyPart.Charset="gb2312"
CDO.Send
Set CDO=Nothing
end if
If Err Then
Response.Write ""&MailAddRecipient&"邮件发送失败!错误原因:" & Err.Description & "<br>"
On Error GoTo 0
End if
End Sub
这个函数你可以选择使用Jmail或者CDO方式发送,如果你需要更多发送的方式,请自行添加诸如ASPMail、Cdont等方式。
CDO和CDONT有什么区别?
CDO是协作数据对像的意思,CDONT是为CDO的一个子集,是为windows NT/2000提供的一个简易版本。
CDO库比CDONT包含了更多的对象,一些与CDONT共同的对象具有更丰富的属性和功能。

订阅我的BLOG(RSS)