PDA

View Full Version : changing from CDONTS to CDOSYS


wedz
02-15-2005, 07:07 AM
Hi fellow developers,

I have run into a problem when changing the platform from older Windows (2000) to windows server 2003. There is an asp page that sends mail using javascript and it used to work ok when using normal CDONTS components. After doing some extensive trial and error and researching from web I have come to a conclusion that I need to use CDOSYS here as CDONTS is deprecated. However I am unable to send the mails anymore.

From other similar threads I have understood that I need to have CDONTS components registered, but I am unfamiliar with ASP and IIS so I am not sure how to do this exactly. Can you please point out to my problem, or if the code is correct guide me how to properly set needed permission etc.

thank you for the effort, here is the javascript code that should send the mails:


var error;
try {
var myMail = Server.CreateObject("cdo.message");
var mailConfig = Server.CreateObject("cdo.configuration");

mailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;
mailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "<here is mailserver address>";
mailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25;

try {
mailConfig.Fields.Update;
} catch (error) {
Response.Write("error updating config<br>");
}

myMail.Configuration = mailConfig;


myMail.From = FromWho;
myMail.To = toWho;
myMail.Cc = CCopy;
myMail.Subject = Subject;
myMail.TextBody = Body;

myMail.Send();


This has been solved now, I was missing "()" from the end of

mailConfig.Fields.Update() ;

Man this was driving me nuts...

miranda
02-15-2005, 08:39 AM
Actually CDONTS predated Win2K and was carried over from WinNT. Win2K also used CDOSYS but many users instead kept using CDONTS. Anyway, I don't know if Win2003 needs this but in Win2K I need the line below for the email to work. This goes above the email code and outside the delimeters <% %>

<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
<%
//your asp code here
%>

I have to ask if you are using Win2003 then why not use .NET instead? sending an email in .NET is much easier to do.


J# .NET method

// Build a MailMessage
System.Web.Mail.MailMessage mailMessage = new System.Web.Mail.MailMessage();
mailMessage.set_From("someone@example.com");
mailMessage.set_To("someone@example.com");
mailMessage.set_Subject("Email Subject");
mailMessage.set_BodyFormat(System.Web.Mail.MailFormat.Text);
mailMessage.set_Body("Your Message Body goes here");

System.Web.Mail.SmtpMail.set_SmtpServer("mail.yourserver.com");
System.Web.Mail.SmtpMail.Send(mailMessage);