Tech Tidbits - Ruby, Ruby On Rails, Merb, .Net, Javascript, jQuery, Ajax, CSS...and other random bits and pieces.

Thursday, October 18, 2007

Classic ASP: Sending e-mail (CDONTS -> CDOSYS)

One of today's jobs was fixing a mail script running on classic ASP that died after being moved to a new server. Attempting to send an email resulted in this error:


Microsoft VBScript runtime error '800a01ad'

ActiveX component can't create object: 'CDONTS.Newmail'

/aspmailer.asp, line 45


CDONTS has been deprecated and replaced with CDOSYS.

I updated aspmailer.asp (a somewhat redundantly named script) to use CDOSYS. After the update, I got this error:


The "SendUsing" configuration value is invalid.


So I still need a bit more code.

This site provided the needed fix:

http://classicasp.aspfaq.com/email/how-do-i-send-e-mail-with-cdo.html


<!--
METADATA
TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library"
-->
<%
Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "<enter_mail.server_here>"
.Update
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = "from@me.com"
.To = "to@me.com"
.Subject = "Sample CDO Message"
.TextBody = "This is a test for CDO.message"
.Send
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>


Replace <enter_mail.server_here> with the name or IP of your SMTP mail server ("localhost" may do the trick).

The other example provided is as follows:


<%
sch = "http://schemas.microsoft.com/cdo/configuration/"

Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserver") = "<enter_mail.server_here>"
.update
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = "from@me.com"
.To = "to@me.com"
.Subject = "Sample CDO Message"
.TextBody = "This is a test for CDO.message"
.Send
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing
%>

No comments:

About Me

My photo
Developer (Ruby on Rails, iOS), musician/composer, Buddhist, HSP, Vegan, Aspie.

Labels