Shortcut Menu

Skip

Main Navigation

Choose your language


ActiveXperts Email Component Add SMTP/POP3 capabilities to any Windows or .NET application

Quicklinks


ActiveXperts Email Component is a software development kit (SDK) that enables the user to send (SMTP) and receive (POP3) e-mail messages. ActiveXperts Email Component supports SMTP, POP3, multiple recipients (To, CC, BCC), multiple attachments (ASCII and binary), rich text body formats (RTF/HTML), Unicode, multiple character sets, SMTP authorization (AUTH PLAIN, AUTH LOGIN, AUTH CRAM MD5), POP3 authorization (Plain, APOP), POP3 header download, different character sets (including arabic, chinese, japanese, russian, greek, hebrew and many more), different encodings (including 7/8 bit, quoted-printable, base64).


Introduction

In this example we are going to create a classic ASP page named 'Default.asp' to receive E-mail messages through the POP3 protocol. This demo project will ask the user for the username and password of the POP3 server where the messages are located.

Step 1: Download and install the ActiveXperts Email Component

Download the ActiveXperts Email Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Web Site

First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on.

From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'. Right-click on the 'Web Sites' container and choose 'New->Web Site':

POP3 ASP

(Click on the picture to enlarge)

The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:

  • Description - a friendly description of the new site;
  • IP / Port / Host Header - choose your preferred way to distinguish between other web sites on the server;
  • Path - select the directory that will store the ASP file(s);
  • Web Site Access Permissions - in the Web Site Access Permissions dialog, enable 'Read' and 'Run scripts (such as ASP)';

You're now able to write an ASP script to receive e-mail using ActiveXperts Email Component.

Step 3: Create the ActiveXperts Email Component objects in ASP

Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor.

<object runat="server" progid="AxEmail.Pop3"            id="objPop3"></object>
<object runat="server" progid="AxEmail.Message"         id="objEmail"></object>
<object runat="server" progid="AxEmail.Constants"       id="objEmailConstants"></object>

Step 4: Test a small piece of ASP

Now, test if your new web site is working well with ActiveXperts Email Component using your browser. If you are using Microsoft Internet Explorer, it is recommended to disable friendly error message because this default setting doesn't show any ASP error message, making it hard to debug if there are any problems:

  • Choose' Internet Options' from the 'Tools' menu;
  • Select the 'Advanced' tab;
  • In the 'Browsing' folder, de-select the 'Show friendly HTTP error messages' option;
  • Click 'OK' to close the dialog.

In this code we will create an 'objPop3' object which is responsible for storing the POP3 information. The 'objEmail' object will contain all the information regarding the e-mail message itself. The 'objEmailConstants' containes information which ir relative to some costant values of the objEmail itself.

Now, use the following piece of code in your DEFAULT.ASP page:

<object runat="server" progid="AxEmail.Pop3"       id="objPop3"></object>
<object runat="server" progid="AxEmail.Message"    id="objEmail"></object>
<object runat="server" progid="AxEmail.Constants"  id="objEmailConstants"></object>

<html xmlns="http://www.w3.org/1999/xhtml" >
  <head>
    <title>ActiveXperts Email Component Demo</title>
    <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
  </head>
  <body>
    <div class="ax_maincontainer">
      <div class="ax_container">
        <h1>Email Component ASP POP3 Sample</h1>
        <hr />
        <form action="pop3.asp" method="post">
          <h2>Email Component:</h2>
          <h3>Build: <% = objPop3.Build %>; Module: <% = objPop3.Module %></h3>
      </div><!-- /container -->
    </div><!-- /maincontainer -->
  </body>
</html>

Test this code with your favorite browser.

Step 5: Receive E-mail messages

The following code will get all the e-mails from the POP3 server and create an array list of messages. This code will only be executed if there was no error while establing the connection.

You can now receive E-mail messages.

(Click on the picture to enlarge)

If (objPop3.LastError = 0) Then
  For i=1 to numMessages
    Set ReceivedMail = objPop3.GetEmailheader(i)
    strResult = objPop3.LastError & ": " & objPop3.GetErrorDescription(objPop3.LastError)
    
    If (objPop3.LastError = 0) Then
      Set arrMessages(i - 1) = ReceivedMail
    End If
  Next
End If

Appendix: Full source code

Following you can find the full source code which is also included in ActiveXperts Email Component package.

<object runat="server" progid="AxEmail.Pop3"            id="objPop3"></object>
<object runat="server" progid="AxEmail.Message"         id="objEmail"></object>
<object runat="server" progid="AxEmail.Constants"       id="objEmailConstants"></object>

<%
  Dim arrMessages()
  strResult = "n/a"

  Set fso = CreateObject("Scripting.FileSystemObject")
  strLogfile = fso.GetSpecialFolder(2) & "\ActiveXperts.Pop3.log"
  objPop3.LogFile = strLogfile

  ' Windows default: "C:\Windows\Temp\ActiveXperts.Pop3.log"

  If(Request("btnSendMessage") <> "") Then
    objPop3.Authentication = objEmailConstants.POP3_AUTH_AUTO
    
    If (objPop3.LastError = 0) Then
      objPop3.Connect Request("txtHost"), Request("txtAccount"), Request("txtPassword")
      strResult = objPop3.LastError & ": " & objPop3.GetErrorDescription(objPop3.LastError)
    End If    

    If (objPop3.LastError = 0) Then
      numMessages = objPop3.CountMessages()
      strResult = objPop3.LastError & ": " & objPop3.GetErrorDescription(objPop3.LastError)

      Dim ReceivedMail
      Redim arrMessages(numMessages - 1)

      If (objPop3.LastError = 0) Then
        For i=1 to numMessages
          Set ReceivedMail = objPop3.GetEmailheader(i)
          strResult = objPop3.LastError & ": " & objPop3.GetErrorDescription(objPop3.LastError)
          
          If (objPop3.LastError = 0) Then
            Set arrMessages(i - 1) = ReceivedMail
          End If
        Next
      End If
    End If
  End If  
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
  <title>ActiveXperts Email Component Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
</head>
<body>
  <div class="ax_maincontainer">
    <div class="ax_header">
      <div class="ax_stroke"></div>
      <div class="ax_logo"></div>
    </div><!-- /header -->

    <div class="ax_container">
      <h1>ActiveXperts Email Component ASP POP3 Sample</h1>
      <hr />
      <p>
      In computing, the Post Office Protocol (POP) is an application-layer Internet standard 
      protocol used by local e-mail clients to retrieve e-mail from a remote server over a 
      TCP/IP connection and uses TCP port 110 by default.<br />
      <br />
      <b>SSL/TLS Encryption does not work in ASP since the default ASP user has no user 
      certificate store.</b>
      </p>
      <form action="pop3.asp" method="post">
        <h2>Email Component:</h2>
        <h3>Build: <% = objPop3.Build %>; Module: <% = objPop3.Module %></h3>

        <!-- Host, Secure -->
        <label for="Host">Mailserver:</label>
        <p>
          <input type="text" id="Host" name="txtHost" value="pop3.mycompany.com" />   
        </p>

        <!-- Account -->
        <label for="Account">Account:</label>
        <p>
            <input type="text" id="Account" name="txtAccount" value="user@mycompany.com" />
            *SSL/TLS Encryption does not work in ASP 
        </p>
        
        <!-- Account Text -->
        <div class="ax_clearLabel"></div>
        <p style="margin-left: 576px; margin-Top:-5px;">
            since the default ASP user has no user certificate store.
        </p>  
        
        <!-- Password -->
        <label for="Password">Password:</label>
        <p>
          <input type="password" id="Password" name="txtPassword" value="" />
        </p>

        <!-- Empty row -->
        <div class="ax_clearRow"></div>

        <!-- List Messages button -->
        <div class="ax_clearLabel"></div>
        <p>
          <input type="submit" name="btnSendMessage" value="List Messages" />
        </p>

        <!-- Messages Listbox -->
        <label for="Received">Messages received:</label>
        <p>
          <select id="Received" name="lvMessages" class="ax_FullWidth" size="10">
          <%
          For each Mail in arrMessages
            Response.Write("<option>" & Mail.Date & ": " & Mail.FromAddress & _
                           "; Subject: " & Mail.Subject & "</Message>")
          Next
          %>
          </select>
        </p>

        <!-- Result -->
        <label for="Result" class="ax_Bold">Result:</label>
        <p>
        <input type="text" id="Result" name="txtResult" class="ax_FullWidth Bold" 
            value="<% = strResult %>" />
        </p>
        
        <!-- Logfile -->
        <label for="Logfile">Logfile:</label>
        <p>
          <input type="text" id="LogFile" name="txtLogFile" class="ax_FullWidth" 
              value="<% = strLogfile %>" />
        </p>
      </form>
      <p>
        This demo uses the ActiveXperts Email Component, an 
        <a href="http://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.
        <br />
        <a href="Default.asp">Back to main page</a>
      </p>
    </div><!-- /container -->
    <div class="ax_footer">
      <div class="ax_icon"></div>
      <p>
        © 2011 <a href="http://activexperts.com" target="_blank">
        Active<font color="#CCC000000">X</font>perts Software B.V.</a> All rights reserved.
        <small>
  <a href="http://activexperts.com/activexperts/contact" target="_blank">Contact Us</a> |
  <a href="http://activexperts.com/activexperts/termsofuse" target="_blank">Terms of Use</a> |
  <a href="http://activexperts.com/activexperts/privacypolicy" target="_blank">Privacy Policy</a>
        </small>
      </p>
    </div><!-- /footer -->
  </div><!-- /maincontainer -->
</body>
</html>

You can download the full source code of this project from the ActiveXperts FTP site: ftp://ftp.activexperts-labs.com/samples/smtp-pop3-component/. There are many other working samples included with the product or on the FTP site.

NOTE: Demo Projects are created with Microsoft Visual Studio 2008

The ActiveXperts Email Component project ships with a set of Microsoft Visual Studio .NET samples. The projects are created with Microsoft Visual Studio 2008.

Users with a later version of Microsoft Visual Studio can open such a project. The Visual Studio Conversion Wizard will guide you through the process of converting the project to the version used.