Solved

Converting from CDONTS to CDOSYS

Posted on 2013-12-16
6
231 Views
Last Modified: 2014-03-01
I have been asked to look at a piece of code which no longer works on a website.  The code generates an email and sends it.  I think the problem is that the site is now on IIS7 which doesnt support CDONTS but I have no idea what im doing trying to convert it.  Ive tried using the godaddy support Godaddy Support but that didnt help.

So the original asp file (sendmail.asp) had (Ive changed the From address for security):-

<script language="javascript" runat="server" src="opendatabase.js"></script>
<script language="javascript" runat="server" src="paramtest.js"></script>
<script language="javascript" runat="server" src="debug.js"></script>
<script language="javascript" runat="server" src="MD5.js"></script>
<script language="javascript" runat="server" src="testlogin.js"></script>

<script language="Javascript" runat="server">

var fromEmail = "admin@testserver.co.uk";

function SendMIMEEMail(toadd,fromadd,subject,body) {
	var objCDO;
	
	try {
		objCDO = Server.CreateObject("CDONTS.NewMail");
	
		objCDO.To		= toadd;
		objCDO.From		= fromadd;
		objCDO.Subject		= subject;
		objCDO.Body		= body;
		objCDO.MailFormat	= 0; //CdoMailFormatMime;
		objCDO.BodyFormat	= 0; //CdoBodyFormatHTML;
		objCDO.Send();
	
		Response.write("{'status':'success'}");
	} catch(e) {
		Response.write("{'status':'error sending email: " + e.description'}");
	}
}

function main() {

	var dbConn,dbRec,SQL;
	
	dbConn = OpenDatabase();
	dbConn.Close();
	
}

</script>

Open in new window


I thought I could do the following but it just shows errors on page when I run it.

<script language="javascript" runat="server" src="opendatabase.js"></script>
<script language="javascript" runat="server" src="paramtest.js"></script>
<script language="javascript" runat="server" src="debug.js"></script>
<script language="javascript" runat="server" src="MD5.js"></script>
<script language="javascript" runat="server" src="testlogin.js"></script>

<script language="Javascript" runat="server">

var fromEmail = "admin@testserver.co.uk";

sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"

set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendurl)=2
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
objConfig.Fields.Update

function SendMIMEEMail(toadd,fromadd,subject,body) {
	var objCDO;
	
	try {
		objCDO = Server.CreateObject("CDO.Message");
	
		objCDO.To		= toadd;
		objCDO.From		= fromadd;
		objCDO.Subject		= subject;
		objCDO.Body		= body;
		objCDO.MailFormat	= 0; //CdoMailFormatMime;
		objCDO.BodyFormat	= 0; //CdoBodyFormatHTML;
		objCDO.Send();
	
		Response.write("{'status':'success'}");
	} catch(e) {
		Response.write("{'status':'error sending email: " + e.description'}");
	}
}

function main() {

	var dbConn,dbRec,SQL;
	
	dbConn = OpenDatabase();
	dbConn.Close();
	
}

</script>

Open in new window


Where am I going wrong?

Thanks
0
Comment
Question by:simonwait
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39722884
The code in the Godaddy article works just fine on a page by itself.  I have it running on several sites.  It could be that the "CDO.Configuration" is not accessible inside that function.

This page http://www.w3schools.com/asp/asp_send_email.asp shows a number of variations for different situations.
0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39723185
Note: Below is vbscript, not jscript

Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = subject 
objMessage.From = fromadd 
objMessage.To = toadd
objMessage.htmlBody = body

'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "relay-hosting.secureserver.net"

'Server port (typically 25) 
'** check your godaddy specs for this
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

objMessage.Send

Open in new window

0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39723400
Oops, I missed that.  The code from Godaddy is Definitely ASP VBscript.  Javascript in the browser can not send email.  This page shows that you can do Jscript on the server but it has to be in ASP blocks <% %>, not <script> tags.
0
 
LVL 1

Author Comment

by:simonwait
ID: 39726659
Thanks for your help.   My ftp¿login for the site isn't working so im not ignoring the help just can't test at the moment
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 39896986
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question