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! |
Achieving true agility is a never-ending effort. We will showcase how you can become agile incrementally, a few practices at the time.Which practices should any agile team strive to adopt? What additional practices should you consider based on your needs to scale? Adopting practices are however made much easier with the right tool support. What about if your tools adapt to your practices? We will take a look at how the Jazz technology can be leveraged to make your process change the behavior of your tools. FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. 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!
|
|
|
|
Because access to government information continues to be an area of concern for many U.S. citizens with disabilities, the U.S. government enacted Section 508 of the Rehabilitation Act in 2001 to ensure that government agencies create accessible Web content, enabling all citizens to access the information they need. A fully accessible Web site makes Web content accessible to all individuals, including those with disabilities, who may be accessing Web content via a variety of user agents. Common user agents include standard Web browsers, text-only browsers, assistive devices and mobile devices such as cell phones or personal digital assistants (PDAs). FREE! Go There Now!
|
|
|
|
This webcast outlines the best practices that must be instituted to gain the maximum benefit from SOA while maintaining high quality of service. Whether you are deploying new applications or managing and monitoring your existing infrastructure, learn how you can ensure high quality of services with SOA based solutions from IBM. All registrants who attend this live Web Seminar will receive complimentary access to a white paper titled “Maintaining QoS in an SOA Environment”. FREE! Go There Now!
|
|
|
|
This whitepaper presents the benefits of successfully introducing static analysis into your organization using IBM Rational Software Analyzer. Additionally, it identifies some common pitfalls that can hinder the effective use of static analysis tooling as well as presents 10 simple strategies designed to help you quickly realize the value of static analysis using Rational Software Analyzer. FREE! Go There Now!
|
|
|
|
This tutorial shows new users of IBM WebSphere Business Monitor Version 6.0.2 how to perform the "Hello World" equivalent for monitoring business process applications. It is intended to help you get familiar with the capabilities of the product. FREE! Go There Now!
|
|
|
|
Hold your calendar on January 30, 2008 for this free webcast on the new i5/OS. Rational's Enterprise Modernization products will be discussed at this webcast as they help to drive the application development environment for this new System i OS. <br />And learn how i5/OS will take you to the next step of efficient, resilient business processing. You will hear about the new i5/OS capabilities as it will be the most significant i5/OS release in years. If you cannot join the webcast on 1/30/08 you can still use this link to listen to the replay.<br /> FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial of the Rational Host Access Transformation Services (HATS) Toolkit. The HATS toolkit provides a set of plug-ins for the IBM Rational Software Delivery Platform to help you easily extend your legacy applications. HATS makes your 3270 and 5250 applications available as HTML through the most popular Web browsers, while converting your host screens to a Web look and feel and it also enables you to develop new Web, portal, and rich-client applications. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |