使用cdo通过外部邮件服务器发邮件 (免安装其他邮件组件)
john peterson [ hooke 编译 ]
win2k下的cdo或cdonts被默认配置成只能通过本地的microsoft smtp服务来发送邮件,如果要用外部的邮件服务器,一般要安装第三方组件。以下代码教你如何利用cdo通过外部邮件服务器发送邮件。(译者win2000下测试通过。)
<%
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) = "sony.com" 改成可用的外部邮件服务器域名
.item(cdosmtpserverport) = 25
.item(cdosmtpconnectiontimeout) = 10
.item(cdosmtpauthenticate) = cdobasic
.item(cdosendusername) = "hooke" 以上服务器的用户名
.item(cdosendpassword) = "mypassword" 密码
.update
end with
set objmessage = server.createobject("cdo.message")
set objmessage.configuration = objconfig
with objmessage
.to = "f4@meteorgardon.com" 改成接收者的邮件地址
.from = "hooke@sony.com" 改成发送人的邮件地址
.subject = "smtp relay test" 标题
.textbody = "smtp relay test sent @ " & now() 正文
.send
end with
set fields = nothing
set objmessage = nothing
set objconfig = nothing
%>
