Click here to Skip to main content
14,173,165 members
Click here to Skip to main content
Add your own
alternative version


52 bookmarked
Posted 15 Nov 2003

Complete ASP / SQL Server / SMTP messaging system

, 15 Nov 2003
Rate this:
Please Sign up or sign in to vote.
A simple email-like system to handle messages posted from an HTML form.



Never give out your email on the web! This solution eliminates the risk of SPAM, viruses and personal email exposure. By using a database to receive the message and SMTP to send a response, you can manage webmaster or other types of email without fear. This system uses a simple HTML form that posts to an ASP page that saves the information into a SQL server database. The messages are then managed using a familiar email like interface and the replies and forwards are sent as native SMTP email.


  • Personal Folders
  • Address Book
  • Actual Email responses
  • Saved Sent Items
  • Column Sorting
  • Simple Integration into existing websites.
  • Works from a simple HTML form
  • No ActiveX or client downloads.


      The idea was to reduce the number of bad emails that were coming into our webmaster email but we wanted to send an actual email response. This system was what I came up with however, once I got started, I couldn't stop. I added all the normal email features (except for attachments) like replies, forwards and personal folders. I also added an address book so you could store contacts and then use them to send the replies and forwards to multiple people.

      Since the address that the SMTP mail is sent from doesn't exist, so there isn't any risk of people responding to it.

      Since I have a content management system that uses a domain_id identifier, I wanted to be able to offer the Webmaster Email program to many of my clients without having to create a database for each one of them, so I added the domain_id identifier to allow many domains to use it without cross contamination. You will see that almost all functions will filter by this identifier.

      The database is SQL Server. I tried to use an access database but I had trouble getting Access to support multiple recordsets in a single SQL call. Instead of describing the database in detail, I have included a script that will build the SQL database. The data_access.asp contains the username and password that is written into the SQL script. These can be changed as long as they are the same in both places. I use a separate config file when I integrate these. For the demo, I simply hard coded them.

      This application is full of some fairly complex code so I hope everyone enjoys perusing it. A lot of the functions and modules can be used in more applications than this one. If you need a native SMTP email creator, I am including mine with this app.

      Using the code


      The code simply needs to be copied to any ASP virtual directory. No global.asa is needed. A database script is provided and just simply needs to be ran on the SQL Server with create database privileges.


      In the install folder include/data_access.asp, simply replace the settings with your server info and you're all set. In my applications, this is an application variable. You may handle it however you wish.


      The application has two parts:

      1. The submit message page that you put out on the public side and an ASP to process the posted data.
        • post.htm
        • update_message.asp
      2. The Webmaster email application that you use internally to see and respond to the messages.

      I have provided a page (default.htm) so you can get to both for demo purposes. It might be a good idea if these are on the same server to secure the webmaster email directory with either a login screen or Windows authentication.


      The SMTP email works by simply placing a structured text file in the mailroot of the server. SMTP needs to be configured on the server for the files to be picked up and actually sent. The code will create the email in a temp directory first and then move the item over. This eliminates the problem of SMTP trying to pick the file up before we are done writing it. I put in some naming functions to ensure uniqueness in a multi-user environment. To configure the paths to these two directories, open mod_main.asp in the include directory and change the path names as needed.


      The database is fairly simple as far as table structures go, but there are some triggers to do cascading deletes and some that manage the read items and notification functions. I had a working copy at one time that sent internal mail with this system and it supported notifications when a person read an item. It also supported priority messages. The database still has fields for these items but I have since removed the code. A clever person could hook this feature back up. Let me know if I can provide any assistance and/or provide some of my old code to let you submit messages internally. Really the only difference is, the internal system had a list of users and the messages were tied to the unique id of those people. Therefore a login was required in order to identify the user and allow each person to read their own mail. There was a series of flags when a sender or a recipient read or deleted an item. I stored settings for each person and allowed them to move the item around separately. To each user, it looked like they were moving their own copy of the message but it was really the same data record being updated.

      The trigger to delete the record once both the recipient and the sender deleted the item from their mailboxes is still in the database.


      1. messages
        [id] [int] IDENTITY (1, 1) NOT NULL ,
        [msg_text] [varchar] (8000) ,
        [user_id] [varchar] (100),
        [last_modified] [datetime] NULL ,
        [active_flg_sender] [int] NULL ,
        [msg_subject] [varchar] (500) NULL ,
        [notify_req] [int] NULL ,
        [was_delivered] [int] NULL ,
        [priority] [int] NULL ,
        [msg_recip] [varchar] (1000) NULL ,
        [folder_id] [int] NULL ,
        [domain_id] [int] NULL ,
        [parent] [int] NULL
      2. msg_folders
        [id] [int] IDENTITY (1, 1) NOT NULL ,
        [folder_name] [varchar] (100) NOT NULL ,
        [domain_id] [int] NOT NULL
      3. msg_recip
        [id] [int] IDENTITY (1, 1) NOT NULL ,
        [recip] [varchar] (50) NULL ,
        [msg_id] [int] NULL ,
        [active_flg_recip] [int] NULL ,
        [msg_read] [int] NULL ,
        [reply_id] [int] NULL ,
        [foward_id] [int] NULL ,
        [read_time] [datetime] NULL ,
        [folder_id] [int] NULL ,
        [reply_date] [datetime] NULL
      4. user_addresses
        [id] [int] IDENTITY (1, 1) NOT NULL ,
        [first_name] [varchar] (50) NULL ,
        [last_name] [varchar] (50) NULL ,
        [email] [varchar] (150) NULL ,
        [domain_id] [int] NULL 


      I have put comments in all the files so they are hopefully self explanatory but just in case, here is a quick summary of the files in the system. I am not including the HTML files in this list simply because there isn't any real code in them. Besides, there is only two: default.htm, and post.htm.

      1. addressbook.asp – This is the main window for the address book. It has an IFRAME for the actual listings.
      2. addresses_inc.asp – This file is inside an IFRAME in the addressbook.asp window. I only do this because I needed a separation so I could have scroll bars.
      3. contactdetail.asp - This file is the input form to add a contact. For this system, I only store the first name, last name and email. You certainly could store whatever you wanted.
      4. inframe.asp – This is the same as default.asp. It can be included in a page or be a main page.
      5. messagedetail.asp – This is the actual message window. It displays just like a regular email window with options to reply and forward the message.
      6. sendmessage.asp – This is the window that pops up if you click reply or forward on a message. It has a button to access the address book for additional addresses. It automatically fills out the “TO” field, the subject (with the classic RE and FW prefaces in place) and the original message.
      7. update_message.asp – This file is used by the public HTML form to post a new message into the system.
      8. updatecontact.asp – This file is the backend code to add/edit and delete a contact.
      9. updatefolder.asp – This file is the backend code to add/edit and delete a personal folder.
      10. updatemessage.asp – This file is the backend code to perform all operations on a message such as reply, forward, move, delete and mark as read. When a message is replied to or forwarded, this file calls the make_email.asp to generate the email text file. For the demo, this has been turned off.
      11. viewmessages.asp – This file is basically the inbox listing. It is included by inframe.asp. It shows all new postings.
      12. viewreadmessages.asp – This file shows all listings that have been read but have not been moved to another personal folder. It is included by inframe.asp.
      13. viewsentmessage.asp – This shows all sent emails. It is included by inframe.asp.
      14. viewpersonalfolder.asp – This is a general personal folder window. It is the same file used by all the personal folders. It shows any message that was moved to a folder regardless if it was read or not. If it was not read, an icon appears next to the unread message.
      15. CDIwm.js – This is a global JavaScript functions module. It is included in almost every file.
      16. mod_main.asp - This is a global include in every ASP page. It is where I put all superfluous functions. It includes the data_access.asp which is the global data connection module. For this application, mod_main is empty but I include it since it is one of my standard architecture components.
      17. data_access.asp - This is a module that I use in all my applications. It contains all the necessary functions to connect easily to a database using ADO. I use it in VB, ASP and even access.
      18. make_email.asp – This is the general-use native SMTP email creation module. It handles all the creating, naming and moving of the file based on the paths configured in mod_main.asp.
    • License

      This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

      A list of licenses authors might use can be found here


      About the Author

      Software Developer (Senior)
      United States United States
      No Biography provided

      You may also be interested in...


      Comments and Discussions

      Generalhi Pin
      yeheyes9-Nov-08 20:13
      memberyeheyes9-Nov-08 20:13 
      GeneralRe: hi Pin
      cdidave10-Nov-08 3:50
      membercdidave10-Nov-08 3:50 
      GeneralRead Msg Pin
      Member 35693398-Mar-07 1:16
      memberMember 35693398-Mar-07 1:16 
      GeneralNo Subject Pin
      Member 35693398-Mar-07 1:15
      memberMember 35693398-Mar-07 1:15 
      GeneralRead Message Pin
      Member 35693398-Mar-07 1:09
      memberMember 35693398-Mar-07 1:09 
      Generalsendmail.asp Pin
      janning19-Jun-06 8:19
      memberjanning19-Jun-06 8:19 
      GeneralRe: sendmail.asp Pin
      janning19-Jun-06 8:20
      memberjanning19-Jun-06 8:20 
      Questionhow to create web sms using asp code Pin
      fadli jaafar1-Apr-06 17:03
      memberfadli jaafar1-Apr-06 17:03 
      QuestionCan you Explain the databases Structure Pin
      Ian Perera22-Oct-05 5:34
      memberIan Perera22-Oct-05 5:34 
      QuestionInternal faux-email system Pin
      dquillan10-Sep-05 23:36
      memberdquillan10-Sep-05 23:36 
      QuestionRe: Internal faux-email system Pin
      PSU Steve9-Feb-16 4:08
      professionalPSU Steve9-Feb-16 4:08 
      GeneralReal Working Example please..... Pin
      UCFirefly2-Sep-05 2:58
      memberUCFirefly2-Sep-05 2:58 
      GeneralError Pin
      Ali Martin22-Feb-05 14:06
      sussAli Martin22-Feb-05 14:06 
      GeneralError Pin
      Member 117676422-Feb-05 14:06
      memberMember 117676422-Feb-05 14:06 
      GeneralUpgrade to the ASP.NET Pin
      Andrzej Budny12-Dec-04 22:16
      memberAndrzej Budny12-Dec-04 22:16 
      GeneralRe: Upgrade to the ASP.NET Pin
      Arjun Paudel22-Jul-08 23:36
      memberArjun Paudel22-Jul-08 23:36 
      Generalwhy the page cannot be displayed Pin
      arena2118-May-04 19:04
      memberarena2118-May-04 19:04 
      QuestionHow about an example with CDOSYS Pin
      Mattcj20-Nov-03 1:34
      memberMattcj20-Nov-03 1:34 
      AnswerRe: How about an example with CDOSYS Pin
      cdidave20-Nov-03 4:43
      membercdidave20-Nov-03 4:43 
      GeneralRe: How about an example with CDOSYS Pin
      Mattcj20-Nov-03 4:51
      memberMattcj20-Nov-03 4:51 
      GeneralRe: How about an example with CDOSYS Pin
      cdidave20-Nov-03 5:03
      membercdidave20-Nov-03 5:03 

      General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

      Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

      Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
      Web04 | 2.8.190524.3 | Last Updated 16 Nov 2003
      Article Copyright 2003 by cdidave
      Everything else Copyright © CodeProject, 1999-2019
      Layout: fixed | fluid