You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Classic ASP:为CDONTS发送邮件实现SMTP身份认证

Can CDONTS Component Support SMTP Authentication?

很遗憾地告诉你,CDONTS(Collaboration Data Objects for NTS)组件本身并不支持SMTP身份认证。

为什么CDONTS做不到?

CDONTS是微软早期为Windows NT开发的轻量级邮件组件,它的设计逻辑完全依赖本地IIS内置的SMTP虚拟服务器来完成邮件发送——它本身不直接和远程SMTP服务器交互,只是把邮件提交到本地SMTP服务,再由本地服务负责转发。这种架构下,它根本没有提供配置SMTP用户名、密码等认证参数的接口,自然无法实现SMTP身份认证。

而且要提醒你,CDONTS已经是被淘汰的组件了:从Windows Server 2003开始微软就逐步弃用它,后续的Windows Server版本(比如2008及以后)默认已经不再包含这个组件,就算你想继续用,在很多现代服务器环境里都无法正常运行。

替代方案:继续使用CDO.Message(你已经实现的方案)

既然你已经通过CDO组件实现了SMTP身份认证,这其实是更靠谱的选择。CDO.Message(属于CDO for Windows 2000,也叫CDOSYS)是CDONTS的替代升级版本,完全支持SMTP身份认证,兼容性也更好。

这里给你一个和你原有CDONTS代码功能对应的CDO.Message带认证示例,方便你参考:

Set objCDO = Server.CreateObject("CDO.Message")
With objCDO
    .To = "testrecipient@domain.com"
    .From = "testsender@domain.com"
    .Subject = "Test Subject"
    .BodyFormat = 0 ' 纯文本格式
    .MailFormat = 0 ' MIME格式
    .Body = "This is a test message"
    .Importance = 0 ' 普通优先级(CDO里0为普通,1为高,2为低,和CDONTS一致)
    
    ' 配置SMTP服务器与认证信息
    With .Configuration.Fields
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your-smtp-server.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587 ' 可根据服务器要求调整端口
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' 使用远程SMTP服务器模式
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 ' 开启基本SMTP认证(2为NTLM认证)
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "your-smtp-username"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "your-smtp-password"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True ' 若服务器要求SSL则设为True
        .Update
    End With
    
    .Send ' 发送邮件
End With

' 清理对象
Set objCDO = Nothing
ReplySent = "Email sent!"
Response.Write(ReplySent)
Response.End

总结

  • CDONTS无法实现SMTP身份认证,且已被官方淘汰;
  • 建议继续使用CDO.Message来实现带SMTP认证的邮件发送,这是更稳定、兼容的方案。

内容的提问来源于stack exchange,提问作者Biju P Dais

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:39:38