asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search










Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Creating a List Server with ASP
By Wayne Berry
Rating: 3.4 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    This Issue

    In this issue we are going to show you how to create an HTML-based list server.

    We use a combination of technologies, including SQL Server, SMTP Server, Active Server and Stephen Genusa's ASPMail Component. The SQL Server is used to store the email address of the participants. The SMTP Server is used to send the outgoing email. Active Server is used to tie the SQL Server, the ASPMail Component and the HTML pages together. Finally we use Stephen Genusa's ASPMail component as a COM interface to the SMTP Server.

    The main work happens in three Active Server pages, with one table in the SQL Server database. But, the magic lies within the ASPMail component, without it we wouldn't be able send email from the Active Server pages.

    Getting Started

    Before getting started you will have to install the ASPMail component and have the Email table and AddEmail store procedure created.

    Subscribing

    To subscribe to the list server, the user goes to an Active Server Page and types in his Email Address. The Active Server page then writes the Email Address to a SQL Server and sends the user a piece of email to confirm that they have been signed up.

    In the confirmation email, there is a URL that the user can click on to unsubscribe from the list server.

    Unsubscribing

    To unsubscribe, the user can click on the URL that comes with his confirmation email address. This URL goes to an Active Server page which removes the users name from the SQL Server Database.

    Alternativly, the user could unsubscribe the same way that they subscribed. That is by typing their email address in an HTML form which submits the address to the Active Server page mentioned above.

    Sending Email

    In order for the administrator to send email to all the users in the list server, there is a separate page that only the list server administrator can get to. This page goes through the database of users one by one and sends each one the same piece of Email.

    ASPMail Component

    ASPMail is an Active Server Component that resides on the Active Server Machine. By using Active Server pages we can call the ASPMail Component and send out email.

    Downloading

    The ASPMail Component can be downloaded from the ASP Developer's Site.

    Creating the Table

    In order to store the email address of the members of the mail list, we need to have a table in SQL Server. Here is what it should look like:

     CREATE TABLE dbo.Email
    (
    Email_Id int IDENTITY NOT NULL PRIMARY KEY,
    Email_Address varchar (75) NULL ,
    Email_Date datetime NULL DEFAULT GetDate()
    )

    AddEmail Stored Procedure

    AddEmail checks to make sure that the email address is not present in the Email table before adding the address. This ensures that the email address isn't added twice. Here is the stored procedure:

     CREATE PROCEDURE AddEmail
    @EmailAddress varchar(75)

    AS

    DECLARE @EmailId int

    SELECT @EmailId=Email_Id
    FROM Email
    WHERE Email_Address=@EmailAddress

    IF (@EmailId IS NULL)
    BEGIN
    INSERT INTO Email (Email_Address) VALUES (@EmailAddress)
    END

    Creating a DSN

    You will need to create an ODBC system DSN on the Internet Information Server that can be used to access the table from the Active Server pages. We called our DSN Email. Make sure that you click on Options >> and put in the database name.

    The Referring Page

    It is recommended that the user first sees an HTML form that can be filled in and submitted to the signup.asp page. This form should use the POST method submitting the user's email address as Email. An Example of this page can be seen in our mailing list sign up and comes with the download of the example.

    Objective

    The objective of the signup.asp page is to allow a user to subscribe to the mailing list by making a call to an Active Server page. This is done in two parts.

    The first step is to generate an email message and send it to the email address that is submitted on the request to the page. If the email doesn't return an error then the email address is added to the database.

    The second step is adding the email address to the database. This is done through a stored procedure call AddEmail, which can be seen in the SQL section. AddEmail makes sure that there is not a duplicate copy of the Email address in the database.

    The Code

    Here is the Code for the page. Notice that you will have to redefine the constants at the top of the page in order for it to work properly.

    
    <%
    ' Configure these constants for your enviorment<BR>
    <BR>
    Const SMTPServer = "smtp.server.com"
    Const ProgramName = "Example Auto Mailer"
    Const ProgramAddress = "webmaster@smtp.server.com"
    Const ExampleVRoot = "http://www.server.com/mailer"
    
    Const SQLDSN = "Email"
    Const SQLLogin = ""
    Const SQLPassword = ""
    
    ' Get Email Address From URL
    EmailAddress=Request.QueryString("Email")
    
    ' Construct Email Body
    StrBody = "This email message is in response to you signing up with " & ProgramName & Chr(13) & Chr(10)
    StrBody = StrBody & "If you want to remove yourself from " & _
     	the mailing list click on the link below:" & Chr(13) & Chr(10)
    StrBody = StrBody & Chr(13) & Chr(10)
    StrBody = StrBody & ExampleVRoot & "/remove.asp?Email=" & EmailAddress & Chr(13) & Chr(10)
    StrBody = StrBody & Chr(13) & Chr(10)
    StrBody = StrBody & "- " & ProgramName & Chr(13) & Chr(10)
    %>
    
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <%
    
    ' Create and configure ASPMail Active Server Component
    Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
    Mailer.RemoteHost  = SMTPServer
    Mailer.FromName = ProgramName
    Mailer.FromAddress = ProgramName & "|" & ProgramAddress
    Mailer.Recipient   = EmailAddress
    Mailer.CC = ProgramAddress
    Mailer.Subject = ProgramName & " Sign Up"
    Mailer.BodyText = StrBody
    Mailer.SMTPLog = "c:\smtplog.txt"
    
    ' Send the Email
    if Mailer.SendMail then
    
    ' Insert the Email Address into the Database
    sql = "EXECUTE AddEmail @EmailAddress='" & EmailAddress & "'"
    
    Set connOnline = Server.CreateObject("ADODB.Connection")
    connOnline.Open SQLDSN,SQLLogin,SQLPassword
    
    Set RS = connOnline.Execute(sql)
    connOnline.Close
    %>
    
    The Email Address has been succesfully added to the mailing list
    <%
    else
    %>
    Error sending Email to <%=EmailAddress%>
    You have not been added to the Emailing List,
    please check the Email Address you submitted and try again
    <%
    End If
    %>
    </BODY>
    </HTML>
    
    

    Objective

    The objective of this page is to allow users to remove their email name using HTTP. In other words, users are allowed to unsubscribe themselves from the mailing list by making a call to an Active Server page.

    This page is not very secure because anyone could remove someone else's name, however they would have to know that the person subscribed to the mailing list to start with. There is opportunity to expand the example to include passwords or compare the cookie and the user name before removing the user.

    The Code

    Here is the Code for the page. Notice that you will have to redefine the constants at the top of the page in order for it to work properly.

    
    <%
    ' Configure these constants for your enviorment
    
    Const  SMTPServer      =       "smtp.server.com"
    Const  ProgramName     =       "Example Auto Mailer"
    Const  ProgramAddress  =       "webmaster@smtp.server.com"
    Const  ExampleVRoot    =       "http://www.server.com/mailer"
    
    Const  SQLDSN          =       "Email"
    Const  SQLLogin        =       ""
    Const  SQLPassword     =       ""
    
    EmailAddress=Request.QueryString("Email")
    
    'Construct the Good-bye Body
    StrBody = "This email message is in response to you removing yourself from" & _
    	 ProgramName & Chr(13) & Chr(10)
    StrBody = StrBody & "If you want to add yourself back to the mailing " & _
    	 "list click on the link below:" & Chr(13) & Chr(10)
    StrBody = StrBody & Chr(13) & Chr(10)
    StrBody = StrBody & ExampleVRoot & "/signup.idc?Email=" & EmailAddress & Chr(13) & Chr(10)
    StrBody = StrBody & Chr(13) & Chr(10)
    StrBody = StrBody & "- " & ProgramName & Chr(13) & Chr(10)
    
    ' Delete the Email Address 
    sql = "DELETE Email WHERE Email_Address='" & EmailAddress & "'"
    
    Set connOnline = Server.CreateObject("ADODB.Connection")
    connOnline.Open SQLDSN,SQLLogin,SQLPassword
    Set RS = connOnline.Execute(sql)
    connOnline.Close
    
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    
    <% Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
    Mailer.RemoteHost  = SMTPServer
    Mailer.FromName    = ProgramName
    Mailer.FromAddress = ProgramName & "|" & ProgramAddress
    Mailer.Recipient   = EmailAddress
    Mailer.CC          = ProgramAddress
    Mailer.Subject     = ProgramName & " Removal"
    Mailer.BodyText    = StrBody
    Mailer.SMTPLog     = "C:\smtplog.txt"
    
    ' Send the Email
    Mailer.SendMail
    %>
    
    <%=EmailAddress%> has been removed from the mailing list
    
    </BODY>
    </HTML>
    
    

    The Referring Page

    It is recommended that send.asp is called from a static .htm page. This static page should contain an HTML form that the Administrator can fill out. The Form should POST to the send.asp page submitting both a Message and a Subject. An example of this page (admin.htm) can be seen in the download.

    Objective

    The send.asp page is used by the administrator of the mailing list only. The send.asp page sends email to all the members of the mailing list. The mailings are sent a piece at a time. This protects the privacy of the members of the mailing list.

    The Code

    Here is the Code for the page. Notice that you will have to redefine the constants at the top of the page in order for it too work properly.

    
    <%
    
    Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
    Set connOnline = Server.CreateObject("ADODB.Connection")
    
    ' Configure these constants for your enviorment
    Const  SMTPServer      =       "smtp.server.com"
    Const  ProgramName     =       "Example Auto Mailer"
    Const  ProgramAddress  =       "webmaster@smtp.server.com"
    Const  ExampleVRoot    =       "http://www.server.com/mailer"
    
    Const  SQLDSN          =       "Email"
    Const  SQLLogin        =       ""
    Const  SQLPassword     =       ""
    
    Message=Request.Form("Message")
    Subject=Request.Form("Subject")
    
    ' Open a SQL Connection
    connOnline.Open SQLDSN,SQLLogin,SQLPassword
    
    ' Initalize the Count
    Count=0
    
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY BGCOLOR=#FFFFFF LINK=#0000FF ALINK=#0000FF VLINK=#0000FF TEXT=#000000>
    Subject: <%=Subject%><BR>
    Message: <%=Message%><P>
    <%
    
    ' Select all addresses to mail to
    sql = "SELECT Email_Address FROM Email"
    
    Set RS = connOnline.Execute(sql)
    
        Do While not RS.eof
    
        ' Get The Email Address from the Server
        EmailAddress=RS("Email_Address")
    
        'Clear The Email Message
        Mailer.ClearBodyText
    
        ' Compose the Email Message
        Mailer.BodyText = "This email message is in response to you signing up with"
        Mailer.BodyText = ProgramName & Chr(13) & Chr(10)
        Mailer.BodyText = "If you want to remove yourself from the mailing list click on the link below:"
        Mailer.BodyText = Chr(13) & Chr(10)
        Mailer.BodyText = Chr(13) & Chr(10)
        Mailer.BodyText = ExampleVRoot & "/remove.asp?Email="
        Mailer.BodyText = EmailAddress & Chr(13) & Chr(10)
        Mailer.BodyText = Chr(13) & Chr(10)
        Mailer.BodyText = Message & Chr(13) & Chr(10)
        Mailer.BodyText = Chr(13) & Chr(10)
        Mailer.BodyText = "- " & ProgramName & Chr(13) & Chr(10)
    
        ' Send the Email Message
        Mailer.RemoteHost  = SMTPServer
        Mailer.FromName    = ProgramName
        Mailer.FromAddress = ProgramName & "|" & ProgramAddress
        Mailer.Recipient   = EmailAddress
        Mailer.CC          = ""
        Mailer.Subject     = Subject
        Mailer.SMTPLog     = "c:\smtplog.txt"
    
        Mailer.SendMail
    
                Count=Count+1
    %>
    <%=Count%>) <%=EmailAddress%> is done!<BR>
    <%
    
        RS.MoveNext
    Loop
    RS.close
    connOnline.Close
    %>
    <P>
    All Done!!
    </BODY>
    </HTML>
    
    

    Download

    You can download the complete source for the sample contained in this issue:

    040697.zip (4K)

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Supporting Products/Tools
    AspEmail
    Free SMTP component that supports multiple file attachments, unlimited recipients, CC's, BCC's and REPLY-TO's. Sends messages as plain text or in the HTML format. Premium features include message queuing and deferred processing for high mail volumes. When used with AspEncrypt, generates S/MIME-enabled secure mail.
    [Top]
    AspMail
    AspMail supports multiple file attachments (MIME and UUE), US ASCII and ISO-8859-1 character sets, 8bit subject lines, custom message content headers, custom message headers, MS Exchange priority headers, PGP and more.
    [Top]
    DevMailer 1.0
    DevMailer adds SMTP email sending abilities to ASP or Perl programs. Features include: attachments, failsafe queueing, redundant servers, standard message file support, and advanced activity logging. Also verify email addresses and send multiple messages on a single connection.
    [Top]
    JangoMail
    JangoMail, located at JangoMail.com, is a web-based service that sends mass e-mails by connecting to data from your SQL Server or ODBC compliant database. Unlike traditional ASP e-mail components, the JangoMail service can also handle unsubscribes and bounces automatically and synchronize these with your original web database. The only setup that is required is the placement of one ASP file on your web server. Other features include message open tracking and click tracking.
    [Top]
    JMail
    Send Email directly from you web page via your webserver. jMail will not start up any annoying email clients, just smoothly send the mail via the mailserver. Implement it with easy ASP code.
    [Top]
    Mail for .NET
    Mail for .NET is the first product for the NetToolworks.NET framework. Together they provide methods that send, receive, compose, edit, encode and decode e-mail messages. SMTP, POP, complex MIME messages, HTML messages, and file/memory streaming are also supported.
    [Top]
    OCXMail
    A single component that is limited in scope to five methods. The OCXMail ASP component allows you to send mail using the standard SMTP protocol from any program that can use ActiveX/OLE components.
    [Top]
    ocxQMail
    The ocxQmail ASP component allows you to send mail using the standard SMTP protocol from any program that can use ActiveX/OLE components. ocxQmail queues up messages for batch delivery by a companion NT Service at intervals you specify in the Administration Windows GUI. Your ASP pages do not have to wait for the mail message to be physically sent before continuing.
    [Top]
    RobustPop3
    RobustPOP3 component allows you to retrieve mail using POP3 protocol. Features include: Retrieve Messages Multiple File Attachments, File Attachments support MIME and UUEncode.
    [Top]
    SA-SmtpMail
    A full-featured SMTP e-mail client component that allows developers to send e-mail from any client. This award-winning control offers significantly better performance than other popular SMTP components. SoftArtisans SMTPmail is written in high-performance C++ and supports all threading models, file attachments and multiple encoding schemes. New features in version 2.0 include login authentication and mass mail. The new version also supports PGP encryption.
    [Top]
    SimpleMail
    Simple mail strictly conforms to the original SMTP standard. It does not support enhanced features like attachments, MIME or multiple character sets. However, it offers high performance, ease of use and a very competitive low price.
    [Top]
    WebMail
    Chilkat WebMail is a POP3/SMTP client component packed with advanced features including: full S/MIME capability, MHTML, multipart/alternative, multipart/related, attachments, advanced AES encryption, charset conversion, Outlook integration, progress monitoring, import EML, import/export XML, mail-merge, distribution lists, Chilkat Zip integration, Outlook contacts and distribution lists, bad email address detection/collection, SMTP Windows Integrated Authorization, smart cards, SMTP/POP3 server diagnostics, full control over Cryptographic Service Providers for S/MIME, auto-handle any charset for any language, and more.
    [Top]
    Other Articles
    Jul 14, 2003 - Creating Efficient Mail Processing Systems - Part 2
    Learn how to run the mail processing component from the first part using Transaction Services provided by COM+ Enterprise Services and see how to use the information available in the SQL Server table to actually send out mail from a Windows Service.
    [Read This Article]  [Top]
    Jul 8, 2003 - Creating Efficient Mail Processing Systems – Part 1
    Many challenges present themselves when trying to send mail as part of a transaction in an enterprise-class application. Fear not frustrated developer. Thiru Thangarathinam will guide you through the steps of designing an extensible and asynchronous mail processing system.
    [Read This Article]  [Top]
    Feb 3, 2003 - Validating E-mail Against the Mail Server
    Calvin Luttrell takes e-mail validation to another level by building a .NET Web service that validates a user's e-mail address against the user's e-mail mail server.
    [Read This Article]  [Top]
    Dec 20, 2002 - Building a .NET E-mail Application - Part 1
    Remie Bolte begins his series on developing .NET SMTP and POP3 e-mail components for an outlook express look-alike Web-based e-mail application. This article provides a thorough overview of the SMTP RFC.
    [Read This Article]  [Top]
    Oct 16, 2001 - Implementing an E-mail Content Filter Using CDO
    Stop SPAM from sliding through your e-mail system. George Walker shows how to create an e-mail content filter for the Windows 2000 SMTP service using Microsoft Collaboration Data Objects.
    [Read This Article]  [Top]
    Oct 2, 2001 - Creating PGP-Encrypted E-Mails
    PGP is an encryption program being used for secure transmission of files and e-mails. This article explains the concepts of PGP, provides details about installing and configuring the command-line version of PGP, and explains how an encrypted e-mail can be generated from ASP.
    [Read This Article]  [Top]
    Jan 20, 2000 - Accessing Outlook 98 Contacts in ASP Pages
    Dennis Adams explains how accessing Outlook 98 Contacts via a Public Folder from ASP pages is possible if attention is paid to properly installing the necessary components, and configuring the IIS and Exchange Server components. Adams offers some prerequisites, a detailed list of sample code segments, and a complete list of reference materials and related Technet articles.
    [Read This Article]  [Top]
    Dec 17, 1999 - How to Send Secure Mail in ASP-Based E-Commerce Applications
    Peter Persits' article explains how Secure Multipurpose Internet Mail Extensions, or S/MIME, has come to rescue of e-commerce Web sites that need some order information to be contained in encrypted E-mail. Customers don't want to use automatic on-line credit card authorization, so order information instead is sent over an SSL-protected HTML form and credit card numbers are sent via encrypted E-mail for manual processing.
    [Read This Article]  [Top]
    Oct 7, 1999 - Using the WSH on the Desktop
    In this article Shahriar Moosavizadeh uses a script to report each day's sales data via E-mail to the sales manager. The Windows Scripting Host allows scripts to be executed directly on the desktop and create a report without having to run the script within the HTML document or ASP page. Included is a sample script that both builds the report and E-mails it to the sales manager, and step-by-step screenshots and instructions.
    [Read This Article]  [Top]
    Mar 25, 1998 - Collaboration Data Object and IIS 4.0
    Collaboration Data Object (CDO) is a COM library designed to send mail through SMTP or Microsoft Exchange. If you install the SMTP server that comes with Microsoft Option Pack 4, you can send mail from an Active Server page using CDO. Because CDO is comes with Microsoft Option Pack 4, CDO is free.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers