用CDO發送簡單電子郵件的例子。很簡單。帶入如下:
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) = "mail.cccar.com.cn" 'smtp伺服器位址
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "使用者名稱" '寄件者的使用者名稱
.Item(cdoSendPassword) = "口令" '寄件者的密碼
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = "ljc@cccar.com.cn" '接收者的郵件地址
.From = "ljc@cccar.com.cn" '寄件者的郵件地址
.Subject = "Test of CDO Sending Email in asp" '郵件的標題
.TextBody = "my email test ,this email is sent by cdo " '郵件的本文
.CC = ljc@oa.cccar.com.cn;sxy@cccar.com.cn '抄送地址
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing