ActiveXperts Email Component

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 send E-mail messages. This demo project will ask the user to give a recipient e-mail address and a message body in the web interface.

Step 1: Download and install ActiveXperts Email Component

Download 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':

SMTP 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 send e-mail using ActiveXperts Email Component.

Step 3: Create 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. On top of the ASP code, insert the following lines to declare and create the Smtp object:

<object runat="server" progid="AxEmail.Smtp"      id="objSmtp"></object>
<object runat="server" progid="AxEmail.Message"   id="objEmail"></object>
<object runat="server" progid="AxEmail.Constants" id="objConstants"></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.

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

<!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 ASP Demo</title>
    
    <object runat="server" progid="AxEmail.Smtp"      id="objSmtp"></object>
    <object runat="server" progid="AxEmail.Message"   id="objEmail"></object>
    <object runat="server" progid="AxEmail.Constants" id="objConstants"></object>

    <title>Email Component Demo</title>
    
  </head>
  <body>
     Email Component version: <% = objSmtp.Version %><br>
     Email Component License Status: <% = objSmtp.LicenseStatus %>
  </body>
</html>

And test it with your favorite browser.

Step 5: Send E-mail messages

You can now send e-mail messages.

(Click on the picture to enlarge)

The following ASP code shows how to send an e-mail message:

If (objEmail.LastError = 0 AND objSmtp.LastError = 0) Then
  objSmtp.Send(objEmail)
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.Smtp"      id="objSmtp"></object>
<object runat="server" progid="AxEmail.Message"   id="objEmail"></object>
<object runat="server" progid="AxEmail.Constants" id="objConstants"></object>

<%
  strResult = "n/a"
  
  strLogfile = fso.GetSpecialFolder(2) & "\AxEmail.Smtp.log"
  Set fso = CreateObject("Scripting.FileSystemObject")
  objSmtp.LogFile =  strLogfile
  ' Windows default: "C:\Windows\Temp\AxEmail.Smtp.log"  
  
  If(Request("btnSendMessage") <> "") Then         
    objEmail.FromName = Request("txtFromName")
    objEmail.FromAddress = Request("txtFromAddress")
    
    If (Request("txtToAddress") <> "") Then
      objEmail.AddTo  Request("txtToAddress"),  Request("txtToAddress")
    End If
    
    If (objEmail.LastError = 0 AND Request("txtCcAddress") <> "") Then     
      objEmail.AddCC  Request("txtCcAddress"),  Request("txtCcAddress")
    End If
    
    If (objEmail.LastError = 0 AND Request("txtBccAddress") <> "") Then    
      objEmail.AddBcc Request("txtBccAddress"), Request("txtBccAddress")
    End If
    
    If (objEmail.LastError = 0) Then
      objEmail.Subject  = Request("txtSubject")
      objEmail.Encoding = Request("ddlEncoding")
      
      Select Case Request("ddlPriority")
        case "Highest Priority"
          objEmail.Priority = objConstants.EMAIL_MESSAGE_PRIORITY_HIGHEST
        case "High Priority"
          objEmail.Priority = objConstants.EMAIL_MESSAGE_PRIORITY_HIGH
        case "Normal Priority"
          objEmail.Priority = objConstants.EMAIL_MESSAGE_PRIORITY_MEDIUM
        case "Low Priority"
          objEmail.Priority = objConstants.EMAIL_MESSAGE_PRIORITY_LOW
        case "Lowest Priority"
          objEmail.Priority = objConstants.EMAIL_MESSAGE_PRIORITY_LOWEST
      End Select
      
      objEmail.BodyPlainText = Request("txtPlainBody")
      objEmail.BodyHtml      = Request("txtHtmlBody")
    End If
    
    If (objEmail.LastError = 0) Then
      objSmtp.Connect Request("txtHost"), Request("txtAccount"), Request("txtPassword")
    End If
    
    If (objEmail.LastError = 0 AND objSmtp.LastError = 0) Then
      objSmtp.Send(objEmail)
    End If
    
    If (objEmail.LastError <> 0) Then
      strResult = objEmail.lastError & ": " & objEmail.GetErrorDescription(objEmail.LastError)
    Else
      strResult = objSmtp.lastError & ": " & objSmtp.GetErrorDescription(objSmtp.LastError)     
    End If
    objSmtp.Disconnect()
  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 SMTP Sample</h1>
      <hr />
      <p>
        Simple Mail Transfer Protocol (SMTP) is an Internet standard for electronic mail (e-mail) 
        transmission across Internet Protocol (IP) networks.
        SMTP is specified for outgoing mail transport and uses TCP port 25 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="smtp.asp" method="post">
        <h2>Email Component:</h2>
        <h3>Build: <% = objSmtp.Build %>; Module: <% = objSmtp.Module %></h3>

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

        <!-- Account -->
        <label for="Account">Account:</label>
        <p>
          <input type="text" id="Account" name="txtAccount" />
          *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" />
        </p>

        <!-- Empty row -->
        <div class="ax_clearRow"></div> 
        
        <!-- Sender Name --> 
        <label for="Sender">Sender name:</label>
        <p>
          <input type="text" id="Sender" name="txtFromName" />
        </p>

        <!-- Sender Email --> 
        <label for="Sender">Sender e-mail:</label>
        <p>
          <input type="text" id="Sender" name="txtFromAddress" />
        </p>

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

        <!-- To -->
        <label for="To">To:</label>
        <p>
          <input type="text" id="To" name="txtToAddress" value="john@mycompany.com" />
        </p>

        <!-- Cc -->
        <label for="Cc">Cc:</label>
        <p>
          <input type="text" id="Cc" name="txtCcAddress" />
        </p>

        <!-- Bcc -->
        <label for="Bcc">Bcc:</label>
        <p>
          <input type="text" id="Bcc" name="txtBccAddress" />
        </p>

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

        <!-- Subject -->
        <label for="Subject">Subject:</label>
        <p>
          <input type="text" id="Subject" name="txtSubject" />
        </p>

        <!-- PlainBody -->
        <label for="PlainBody">Body:</label>
        <p>
          <textarea id="PlainBody" name="txtPlainBody" style="height: 60px;"></textarea>
        </p>

        <!-- HtmlBody -->
        <label for="HtmlBody">Body HTML (optional):</label>
        <p>
          <textarea id="HtmlBody" name="txtHtmlBody" style="height: 60px;"></textarea>
        </p>

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

        <!-- Char. Set -->
        <label for="CharSet">Char. Set:</label>
        <p>
          <select name="ddlEncoding">
            <option value="0">Standard</option>
            <option value="65001">UTF8</option>
          </select>
        </p>

        <!-- Priority -->
        <label for="Priority">Priority:</label>
        <p>
          <select name="ddlPriority">
            <option>Highest Priority</option>
            <option>High Priority</option>
            <option selected="true">Normal Priority</option>
            <option>Low Priority</option>
            <option>Lowest Priority</option>
          </select>
        </p>

        <!-- SendButton -->
        <div class="ax_clearLabel"></div>
        <p>
          <input type="submit" name="btnSendMessage" value="Send Message" />
        </p>

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

        <!-- Result -->
        <label for="Result"class="ax_Bold">Result:</label>
        <p>
          <input type="text" id="Result" class="ax_FullWidth Bold" name="txtResult" 
            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.