E-mail (CDONTS.NewMail) Sample Code
The form at the start page of my articles contains an e-mail form which sends form information to an
e-mail ASP processing page called email.asp. It's pretty simple and sending e-mail via ASP and
IIS' SMTP Service is a breeze.
If you have the SMTP Service setup and started (with the SmartHost set to point to a SMTP server),
you can use the COM Component CDONTS.NewMail in your ASP pages to send e-mail to recipients!
Click HERE to download a self-extracting ZIP file that contains
the email.asp page I use with the form mentioned above.
Below is the sample in JavaScript (which is what I write most of my ASP in):
if (Request.Form("msg") == "")
{
Response.Write("
Oopps.. you didn't type a message!
" +
"Click here to go back.")
}
else
{
var objMail = Server.CreateObject("CDONTS.NewMail");
objMail.To = "someone@somewhere.com"; //<-- PUT A VALID E-MAIL ADDRESS HERE
objMail.From = "someone@somewhere.com"; //<-- PUT A VALID E-MAIL ADDRESS HERE
objMail.Subject = "Message from ASP Alliance Visitor";
objMail.Body = Request.Form("msg");
objMail.Send()
var objMail = null;
Response.Write("
Thank you for your message!
" +
"An e-mail has been delivered to my e-mail address (miketgonzalez@yahoo.com) with " +
"the following message: " + Request.Form("msg") + "
" +
"Click here to go back.")
}
Below is the sample in VBScript:
If Not Request.Form("msg") <> "" Then
Response.Write("
Oopps.. you didn't type a message!
" & _
"Click here to go back.")
Else
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.To = "someone@somewhere.com" '<-- PUT A VALID E-MAIL ADDRESS HERE
objMail.From = "someone@somewhere.com" '<-- PUT A VALID E-MAIL ADDRESS HERE
objMail.Subject = "Message from ASP Alliance Visitor"
objMail.Body = Request.Form("msg")
objMail.Send()
Set objMail = Nothing
Response.Write("
Thank you for your message!
" & _
"An e-mail has been delivered to my e-mail address (miketgonzalez@yahoo.com) with " & _
"the following message: " & Request.Form("msg") & "
" & _
"Click here to go back.")
End If
|