Solved

Converting from CDONTS to CDOSYS

Posted on 2013-12-16
6
225 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 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 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 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Out the count variables 6 53
HTML in email body has extra  tick marks 3 64
XML Parsing Classic ASP 5 51
Question about ASP Including Files 6 44
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now