Article View: comp.lang.javascript
Article #19Re: Sending a CDONTS email
From: kaeli
Date: Thu, 25 Jul 2002 13:25
Date: Thu, 25 Jul 2002 13:25
72 lines
3087 bytes
3087 bytes
Ben wrote:
> Hi Guys,
>
> Can anyone help! I am trying to put together a basic cookie in JavaScript.
> The cookie part of the script it working perfectly, no problems there.
> However after the cookie has been executed I want the script to send an
> email using CDONTS. This is where I am having problems.
>
> I only want the email to be sent if the cookie is executed ie if it exists.
> Currently nothing is working, if I take out the email side of the script the
> cookie works, but I need both running.
>
> Any ideas where I am going wrong?
>
Yeah, using server side commands like Server.CreateObject with a
client-side script.
If you have CDONTS, you have ASP. Use that. Server-side VBScript or
JScript is much better for mail than a client-side language that
requires someone have an e-mail client installed and associated with
their browser.
Try the following, tested in IIS/Win2K/IE6 successfully (modify the from and to addresses appropriately).
HTH
kaeli
<%@ LANGUAGE="JSCRIPT"%>
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>test </title>
</head>
<body>
<%
//page to go to if cookie exists
go_to = "software.htm";
//number of days cookie lives for
num_days = 1;
function ged(noDays){
var today = new Date();
var expr = new Date(today.getTime() + noDays*24*60*60*1000);
return expr.toGMTString();
}
function readCookie(cookieName){
var start = Request.Cookies(cookieName);
if (start == ""){
Response.Cookies("seenit")="yes; expires=" + ged(num_days);
} else {
Response.Redirect(go_to);
}
}
readCookie("seenit");
// now send the email using CDONTS
var sendmailMsg = Server.CreateObject("CDONTS.NewMail");
sendmailMsg.From = "email@email.com";
sendmailMsg.To = "mail@mail.com";
sendmailMsg.subject = "Subject";
sendmailMsg.body = "Body";
sendmailMsg.send();
%>
</body>
</html>
Technical Details
Message-ID:
<3D3FFC49.5060804@NOSPAMatt.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone1.gnilink.net!wn3feed!worldnet.att.net!207.24.196.41!nntphub.cb.lucent.com!newsReferences:
<ahmnhu$cg$1@news5.svr.pol.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 100e17,c1c4460db7d5ea6e X-Google-Attributes: gid100e17,public X-Google-Thread: fb3cb,c1c4460db7d5ea6e X-Google-Attributes: gidfb3cb,public X-Google-ArrivalTime: 2002-07-25 06:27:47 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed1.cidera.com!Cidera!cyclone1.gnilink.net!wn3feed!worldnet.att.net!207.24.196.41!nntphub.cb.lucent.com!news From: kaeli <infinite.possibilitiesNOSPAM@NOSPAMatt.net> Newsgroups: comp.lang.javascript,alive.internet.lang.javascript Subject: Re: Sending a CDONTS email Date: Thu, 25 Jul 2002 08:25:29 -0500 Organization: Lucent Technologies, Columbus, Ohio Lines: 73 Message-ID: <3D3FFC49.5060804@NOSPAMatt.net> References: <ahmnhu$cg$1@news5.svr.pol.co.uk> NNTP-Posting-Host: il0015nhunn03.ih.lucent.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:0.9.4) Gecko/20011019 Netscape6/6.2 X-Accept-Language: en-us