Santry Technology Solutions, Content Management, DotNetNuke, SharePoint Consulting
Register | Login
Wednesday, January 07, 2009

Sections
  
About Us
  
Partners
Downloads
  
 WWWCoder.com Resource Directory

Sending Mail
9/8/2000 10:02:37 PM

This article covers sending mail using the SMTP server that comes with IIS and the file system object with ASP. No third-party COM objects are needed to send Internet mail using this method.

An email message is simply a text file. In order for an SMTP server to send the file to its destination it must be placed in the SMTP server’s outbound queue directory. In this example we will create a text file that adheres to SMTP and save it in IIS outbound SMTP queue. This method is very simple to implement and doesn’t require an installation of a supporting component.

To begin create two files one file that contains the HTML form for entering in the email message, and then another page to contain the ASP code for creating the text file to drop in the SMTP pickup directory.


Below is the file that contains the HTML form code for passing our email information to the processing ASP script.


<html>
<head>
<title>Send Mail</title>
</head>
<body> 


<form method="POST" action="sendmail.asp">
  <pre>Send to Email: <input type="text" name="email" size="20">
Subject:       <input type="text" name="subject" size="20"></pre>
  <pre>Message:
<textarea rows="7" name="message" cols="42"></textarea></pre>
  <p><input type="submit" value="Submit" name="B1">
<input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>


Then create a new file in the same directory as the HTML form file called sendmail.asp. This file will be used for processing the form values and creating an email file for sending. The code entered into the sendmail.asp file is as follows:


<%
Dim strHTML



Sub CreateEmail
     On Error Resume Next
     Dim strMessage, strEmail, strSubject, tempMessage, MyEmailFile
     Dim FSO, TS
     'populate the variables with form values.
     strMessage = Request.Form("message")
     strEmail = Request.Form("email")
     strSubject = Request.Form("subject")
    'now build the message structure.
     tempMessage = "x-sender: Patrick@Santry.com" & vbcrlf & _
          "x-receiver: " & strEmail & vbcrlf & _
          "From: Patrick@Santry.com" & vbcrlf & _
          "To: " & strEmail & vbcrlf & _
          "Subject: " & strSubject & vbcrlf & vbcrlf & _
          strMessage 


     MyEmailFile = "c:\inetpub\mailroot\pickup\message.txt"
     Set FSO = Server.CreateObject("Scripting.FileSystemObject")
     Set TS = FSO.CreateTextFile(MyEmailFile, True)
     TS.Write tempMessage
     TS.Close
     Set FSO = Nothing
     Set TS = Nothing
     If Err <> 0 Then
          strHTML = "An error occurred sending “ & _
               
“ this message: <br>" & vbcrlf & _
          "Description: " & Err.Description
     Else
          strHTML = "Message was sent!"
     End If
End Sub


CreateEmail
%>


<html>
<head>
<title>Message Status</title>
</head>
<body>


<%= strHTML %>


</body>
</html>


The sendmail.asp file contains one subroutine called CreateEmail. This subroutine accepts the values that were passed from the form file and uses them to create an SMTP compliant text file. Once the string for the contents of the file is built it then passed to the FileSystemObject in order to create the message file and save it into the pickup directory where the SMTP service will check periodically and send messages within it.


 Note: You may want to name the file something other than message.txt if you plan on high traffic accessing this script. This way you won’t overwrite the file with a new message if the SMTP server didn’t pick up the message yet. Try naming the file based on time, or some other way of providing a unique name.

By: Patrick Santry, Microsoft MVP (ASP/ASP.NET), developer of this site, author of books on Web technologies, and member of the DotNetNuke core development team. If you're interested in the services provided by Patrick, visit his company Website at Santry.com.

Related Articles
   Related Document Sending Email from your .Net Application
   Related Document Exposing NNTP in Your Web


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 10/19/2005 11:02:32 AM by Anonymous
Comments: Message got to Queue subfolder of mailroot and stands there. Receiver never got it.
Left on 12/17/2004 12:15:44 AM by Anonymous
Comments: is it require to configure the SMTP server to send an email?
Left on 12/4/2004 10:06:45 PM by Anonymous
Comments: not very much
Left on 11/28/2004 12:41:42 PM by Anonymous
Comments: i just want to know what to go to in order to send e-mail
Left on 11/5/2004 10:58:24 AM by Anonymous
Comments: gamarjoba
Left on 11/4/2004 8:23:44 PM by Anonymous
Comments: Hi prea>
Left on 9/24/2004 5:44:50 PM by Anonymous
Comments: Yes, I would love to send mail on Yahoo!. But, how do you send mail to your friends and to the ones who you really love?
Left on 3/10/2004 12:59:30 PM by Anonymous
Comments: great job write some more
Left on 8/17/2003 10:19:01 AM by Anonymous
Comments: good
Left on 8/17/2003 10:18:57 AM by Anonymous
Comments: good
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970