Solved

Converting from CDONTS to CDOSYS

Posted on 2013-12-16
6
223 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
6 Comments
 
LVL 82

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 52

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 82

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 32

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now