<%
class sentmail
'var sendmail test,emptyvar
'creat by qqlxinye@tom.com
'time 2008-09-19
'qq:273453129
dim outSmtp,outUser,outPsd,recUser,recSubmit,bodyContent,AddAttachment,ifsend
function init_mail(str1,str2,str3,str4,str5,str6,str7)
outSmtp=str1
outUser=str2
outPsd=str3
recUser=str4
recSubmit=str5
bodyContent=str6
AddAttachment=str7
if isnull(outSmtp)or isnull(outUser)or isnull(outPsd) or isnull(recUser) or isnull(recSubmit) or isnull(bodyContent) then
ifsend=false
end if
end function
function send()
if not ifsend then
Const cdoSendUsingMethod=" http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort=2
Const cdoSMTPServer=" http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort=" http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout=" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate=" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic=1
Const cdoSendUserName=" http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword=" http://schemas.microsoft.com/cdo/configuration/sendpassword"
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) =outSmtp
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = outUser
.Item(cdoSendPassword) = outPsd
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
On Error Resume Next
With objMessage
.To =recUser
.From =outUser
.Subject = recSubmit
'.TextBody = bodyContent
.HTMLBody=bodyContent
'.AddAttachment "C:/Scripts/Output.txt"'邮件附件
.Send
End With
On Error GoTo 0
if err.description<>""then
response.Write "aaa"
end if
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
end if
end function
end class
%>
class sentmail
'var sendmail test,emptyvar
'creat by qqlxinye@tom.com
'time 2008-09-19
'qq:273453129
dim outSmtp,outUser,outPsd,recUser,recSubmit,bodyContent,AddAttachment,ifsend
function init_mail(str1,str2,str3,str4,str5,str6,str7)
outSmtp=str1
outUser=str2
outPsd=str3
recUser=str4
recSubmit=str5
bodyContent=str6
AddAttachment=str7
if isnull(outSmtp)or isnull(outUser)or isnull(outPsd) or isnull(recUser) or isnull(recSubmit) or isnull(bodyContent) then
ifsend=false
end if
end function
function send()
if not ifsend then
Const cdoSendUsingMethod=" http://schemas.microsoft.com/cdo/configuration/sendusing"
Const cdoSendUsingPort=2
Const cdoSMTPServer=" http://schemas.microsoft.com/cdo/configuration/smtpserver"
Const cdoSMTPServerPort=" http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Const cdoSMTPConnectionTimeout=" http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Const cdoSMTPAuthenticate=" http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Const cdoBasic=1
Const cdoSendUserName=" http://schemas.microsoft.com/cdo/configuration/sendusername"
Const cdoSendPassword=" http://schemas.microsoft.com/cdo/configuration/sendpassword"
Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) =outSmtp
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = outUser
.Item(cdoSendPassword) = outPsd
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
On Error Resume Next
With objMessage
.To =recUser
.From =outUser
.Subject = recSubmit
'.TextBody = bodyContent
.HTMLBody=bodyContent
'.AddAttachment "C:/Scripts/Output.txt"'邮件附件
.Send
End With
On Error GoTo 0
if err.description<>""then
response.Write "aaa"
end if
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
end if
end function
end class
%>
<!--发送测试代码
set mail=new sentmail
mail.init_mail "smtp 服务器","smtp 服务器上的邮箱","smtp 服务器上的邮箱的密码","收信人地址","主题","正文内容",null
null这参数暂时不用,但发送时还是要写上,共7个参数
mail.send
例如:
<%
set mail=new sentmail
mail.init_mail "smtp.tom.com","qqlxinye@qq.com","123456","273453129@qq.com","test","<html><body><p align='center'><b>Hey 'there!</b></p><p align='center'><b>This is a html doc in your Email!!!!</b></p><p align='center'> </p><p align='center'>' </p><p align='center'><i><u>We kick the Llamas Ass!!!!</u></i></p></body></html>","<font color=red>test</font>"
mail.send
%>
-->
<%
set mail=new sentmail
mail.init_mail "smtp.tom.com","qqlxinye@qq.com","123456","273453129@qq.com","test","<html><body><p align='center'><b>Hey 'there!</b></p><p align='center'><b>This is a html doc in your Email!!!!</b></p><p align='center'> </p><p align='center'>' </p><p align='center'><i><u>We kick the Llamas Ass!!!!</u></i></p></body></html>","<font color=red>test</font>"
mail.send
%>
-->
上面两段ASP可以放在一个send.asp中,然后在邮件内容书写页的form里把action设为send.asp