I get lots of emails on how to send email from an ASP page. Well there is lots of 3rd party components that you can buy. Which I've never boughten so I can't comment on them but I figure Why buy when IIS 4.0 comes with SMTP service. SMTP stands for Simple Mail Transfer Protocol, this is the agent that sends the mail to whatever address you give it.
This service is added for FREE!! Yes FREE! And comes with the CDONTS object. For the human person this object allows you to set some things up to send a simple email very painless and quickly. The demo below shows how quickly you can setup a basic input page and an ASP page to send the mail.
Some assumpsions before we get started:
- Server running NT 4.0 w/service pak 3 or greater
- IIS 4.0 w/SMTP service installed and setup to point to the SMTP Server.
- For questions on how to exactly setup the SMTP service, check the NT Option pak 4.0 documentation-under Microsoft Internet Information Server. There is a whole section on the SMTP service as well others. This is how I figured out how to setup the service on the Server.(AND I ain't no ADMIN) or the standard consult your Network Admin!! This demo just helps you with the code that sends the mail. :)
Step 1: Create the Input Form:
'Create yourself and input form like this one below lets call this Mail_Input.htm
'Code for this page copy and paste if needed-Save you from coding.
'Easy thing to do is open a new notepad text document and copy & paste this into the new document
'Save As MailInput.htm to your web directory and poof new input document for FREE!
<html>
<head><title>Mail Input Page</title></head>
<body>
<form method="post" action="sendmail.asp" name="Inputform">
<table border="1" width="50%">
<tr><td width="48%">From</td>
<td width="52%"> <input type="text" name="From" size="20"></td></tr>
<tr><td width="48%">To</td><td width="52%"><input type="text" name="to" size="20"></td></tr>
<tr><td width="48%">Subject</td><td width="52%"><input type="text" name="subject" size="20"></td></tr>
<tr><td width="48%">Body</td><td width="52%"><input type="text" name="body" size="20"></td></tr>
<tr><td width="48%"><input type="submit" value="Send" name="B1"><input type="reset"value="Reset" name="B2"></td>
<td width="52%"> </td></tr>
</table>
</form>
</body>
</html>
Step 2: Create the ASP Page: sendmail.asp
Create a 2nd new page and save as sendmail.asp to your web directory. Below is the code that does the server side work to read the information and send the message.
<%
'Declare local variables to hold the data from the Input form page that is used above.
Dim strTo
Dim strSubject
Dim strBody 'Strings for recipient, subject, boby
Dim objCDOMail 'The CDO object
'First we'll read in the values entered from the form into the Local variables
strFrom = Request.Form("From") 'Make sure the From field has no spaces.
strTo = Request.Form("to")
strSubject = Request.Form("subject")
strBody = Request.Form("body")
' Create an instance of the NewMail object.
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
' Set the properties of the object
objCDOMail.From = StrFrom
objCDOMail.To = strTo
objCDOMail.Subject = strSubject
objCDOMail.Body = strBody
' There are lots of other properties you can use.
' You can send HTML e-mail, attachments, etc...
' You can also modify most aspects of the message
' like importance, custom headers, ...
' Check the help files for a full list as well
' and the correct syntax.
' Some of the more useful ones I've included samples of here:
'objCDOMail.Cc = "mailto:sschofield@aspfree.com;steve@aspfree.com" Notice this sending to more than one person!
'objCDOMail.Bcc = "sschofield@aspfree.com;steve@aspfree.com"
'objCDOMail.Importance = 1 '(0=Low, 1=Normal, 2=High)im a
'objCDOMail.AttachFile "c:\path\filename.txt", "filename.txt"
' Send the message!
objCDOMail.Send
' Set the object to nothing because it immediately becomes
' invalid after calling the Send method + it clears it out of the Server's Memory.
Set objCDOMail = Nothing
%>
<html>
<head><title>Sent Mail</title></head>
<body>
Your mail was sent to:<% = request("to") %><br>
The time that is was sent was: <% = Now %>
</body>
</html>
Good luck!
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles
More By aspfree
developerWorks - FREE Tools! |
Join this Rational Talks to You teleconference, featuring Paul Boustany and Mark Krasovich, to speak to the experts about becoming a Rational ClearCase power user. Get a chance to ask your questions and learn tips and tricks for using Rational ClearCase in Agile development FREE! Go There Now!
|
|
|
|
David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Learn to enable users to both rate existing animations and to combine existing animations into new snippets. This is the third in a series of three tutorials that chronicle the building of a site that enables collaborative discussion and animation building using Domino and OpenLaszlo. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
|
|
|
|
In this tutorial, you can learn how to install and configure the IBM Rational Asset Manager Eclipse client, explore the different views in the Asset Management perspective, learn various search techniques, work with existing assets, and submit a new asset. FREE! Go There Now!
|
|
|
|
Learn how to implement a build management system that uses and extends your existing automation technologies. This tutorial shows, step-by-step, how to install and configure IBM Rational Build Forge to manage builds for Jakarta Tomcat from source code. FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
|
|
|
|
IBM Lotus Notes 8 provides a wide range of developers the ability to provide customized, integrated user interfaces via composite applications and via custom sidebar and toolbar plug-ins. This webcast provides you with tips and techniques to use with out-of-the-box capabilities of Lotus Notes 8, and survey how you can share useful components within your own company and within a larger community. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |