ASP中使用CDO.Message+SMTP發(fā)送郵件的函數(shù)代碼分享
作者: 來(lái)源: 發(fā)布時(shí)間:2011-6-15 11:51:02 點(diǎn)擊:
下面提供給大家分享的是關(guān)于在ASP中使用CDO.Message+SMTP發(fā)送郵件的函數(shù)代碼,希望能對(duì)大家有所幫助。
<!--發(fā)送代碼-->
<%
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) = "SMTP服務(wù)器" '改成可用的外部郵件服務(wù)器域名
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "用戶名" '以上服務(wù)器的用戶名
.Item(cdoSendPassword) = "密碼" '密碼
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = Trim(Request.Form("m_user")) '改成接收者的郵件地址
.From = "發(fā)件人的地址(要和上面的郵件系統(tǒng)相同)" '改成發(fā)送人的郵件地址
.Subject = Trim(Request.Form("m_zhuzi")) '標(biāo)題
.TextBody = Trim(Request.Form("m_neirong")) '正文
'.AddAttachment "C:\Scripts\Output.txt"'郵件附件
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>
<!--發(fā)送代碼-->
<%
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) = "SMTP服務(wù)器" '改成可用的外部郵件服務(wù)器域名
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "用戶名" '以上服務(wù)器的用戶名
.Item(cdoSendPassword) = "密碼" '密碼
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = Trim(Request.Form("m_user")) '改成接收者的郵件地址
.From = "發(fā)件人的地址(要和上面的郵件系統(tǒng)相同)" '改成發(fā)送人的郵件地址
.Subject = Trim(Request.Form("m_zhuzi")) '標(biāo)題
.TextBody = Trim(Request.Form("m_neirong")) '正文
'.AddAttachment "C:\Scripts\Output.txt"'郵件附件
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>
<!--發(fā)送代碼-->
[收藏此文章]