如何在asp网页中添加CDO引用

时间:2011-03-12 00:31:26

标签: asp-classic cdo.message cdonts

我正在尝试在asp中创建一个新电子邮件,并使用CDO将其发送到邮件服务器。我相信我需要CDO或发送电子邮件功能的参考。在书中它说使用这个:

Set objNewMail = Server.CreateObject("CDONTS.NewMail")

不幸的是,现在正在运行,因为它在asp中出错了。现在确定如何添加引用或com对象,以便它可以通过使用asp的iis工作。我所指的那本书是:ASP在坚果壳中的第二个补充。 “CDO对象模型”我使用的是Windows XP或Windows Server 2003。

1 个答案:

答案 0 :(得分:1)

使用此代替cdonts

<!--
    METADATA        
    TYPE="typelib"        
    UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"        
    NAME="CDO for Windows 2000 Library"
-->

<%
Function SendMail(sFrom, ToA, Subject, Mybody)

     Dim iMsg,iConf      
     Set iMsg  = CreateObject("CDO.Message")         
     Set iConf = CreateObject("CDO.Configuration")

     Dim Flds        
     Set Flds = iConf.Fields    
     With Flds       
       ' assume constants are defined within script file       
       .Item(cdoSendUsingMethod)   = cdoSendUsingPort          
       .Item(cdoSMTPServer)        = MAILSERVER        
       .Item(cdoSMTPConnectionTimeout) = 60            
       .Item(cdoURLGetLatestVersion)   = True          
       .Update         
     End With

     With iMsg       
       Set .Configuration = iConf          
           .To       = ToA             
           .From     = sFrom               
           .Subject  = Subject             
           .TextBody = Mybody              
           .Send               
     End With

     Set iConf = nothing         
     Set iMsg = nothing

    If Err.Number = 0 Then      
      SendMail = True           
    Else        
     SendMail = Err.Number&":"&Err.Description          
    End If
    On Error Goto 0    
    set objSendMail = Nothing       
End Function    

%>