Search code examples
asp-classiccdo.messagecdonts

How to add CDO reference in an asp web page


I'm trying to create a new email in asp and send it to a mail server using CDO. I believe I need a reference for CDO or Send Email functionality. In the book it says use this:

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

Unfortunately that is now working as it errors out in asp. Now sure how to add the reference, or com object so that it will work through iis using asp. The book I'm referring to is: ASP In a nut shell 2nd addition. "The CDO Object Model" I'm using windows xp or windows server 2003.


Solution

  • use this instead of 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    
    
    %>