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

This document describes how ActiveXperts Email Component can be integrated into HTML projects. This demo project will ask the user to give an e-mail address and a message body on the command prompt.

Step 1: Installation of ActiveXperts Email Component

When using HTML, there are two ways to install ActiveXperts Email Component on a client PC:

  • Automatically using HTML code;
  • Using ActiveXperts Email Component InstallShield installation.

Automatic installation using HTML code

You can install ActiveXperts Email Component automatically using the following HTML code on top of the HTML page:

<object codebase="http://www.activexperts.com/files/smtp-pop3-component/cab/4.0/AxEmail.cab"
         classid="CLSID:1A129FBB-C9B4-43F7-8352-30CEF860AD8A" ></object>

The Email Component will be installated automatically. The user will be asked to confirm the installation, because the DLL is coming from an untrusted site (www.activexperts.com). There are two ways to avoid prompting:

  • Add the ActiveX/COM location to the user's trusted sites. You can manage trusted manually (by using the Internet Explorer), through a logon script (by appyling the registry change from the logon script) or by using Active Directory Group Policies;
  • Or use a trusted location for the DLL. For instance your Intranet site, because most probably this site has already been added to the list of trusted sites for all users.

Manual installation using ActiveXperts Email Component installation procedure

On each client PC, download ActiveXperts Email Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create the E-mail objects in HTML

You must use Javascript to declare and create the objects.

Use the following Javascript code to declare and create the objSmtpServer object:

var objSmtp      = new ActiveXObject("AxEmail.Smtp");
var objConstants = new ActiveXObject("AxEmail.Constants");
var objEmail     = new ActiveXObject("AxEmail.Message");

Step 3: Gather information

The following code will ask the user for the recipient e-mail address and the content of the text message. You can also specify a CC or BCC recipient and you can also add an attachment to your message. This data will be stored in the 'objEmail' object.

objEmail.FromName = objForm.txtFromName.value;
objEmail.FromAddress = objForm.txtFromAddress.value;

if (objForm.txtToAddress.value != "")
{
  objEmail.AddTo (objForm.txtToAddress.value,  objForm.txtToAddress.value);
}

if (objForm.txtCcAddress.value != "" && objEmail.LastError == 0)
{
  objEmail.AddCc (objForm.txtCcAddress.value,  objForm.txtCcAddress.value);
}

if (objForm.txtBccAddress.value != "" && objEmail.LastError == 0)
{
  objEmail.AddBcc(objForm.txtBccAddress.value, objForm.txtBccAddress.value);
}

if (objEmail.LastError == 0)
{
  objEmail.Subject  = objForm.txtSubject.value;
  objEmail.Priority = objForm.ddlPriority.value;
  objEmail.Encoding = objForm.ddlEncoding.value;
  
  objEmail.BodyPlainText  = objForm.txtPlainBody.value;
  objEmail.BodyHtml       = objForm.txtHtmlBody.value;
  
  if (objForm.cbxSecure.checked == 1)
  objSmtp.SetSecure(465); // 465 is the generic secure SMTP port
}

Step 4: Send E-mail messages

The following code shows how to send an e-mail message using the data that was stored in the 'objEmail' object.

objSmtp.Send(objEmail);

Appendix: Full source code

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

<!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 Javascript Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
  
  <object codebase="http://www.activexperts.com/files/smtp-pop3-component/cab/4.0/AxEmail32.cab" 
    classid="CLSID:1A129FBB-C9B4-43F7-8352-30CEF860AD8A" ></object>
  <script language="JavaScript" type="text/javascript">
    var objSmtp = new ActiveXObject("AxEmail.Smtp");
    var objConstants = new ActiveXObject("AxEmail.Constants");
    
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    objSmtp.LogFile = fso.GetSpecialFolder(2) + "\\AxEmail.Smtp.log";
    // Windows default: 'C:\Users\%USERNAME%\AppData\Local\Temp\AxEmail.Smtp.log'
    
    window.attachEvent("onload", PageLoaded, false);
    
    function PageLoaded() {
      document.getElementById("APIinfo").innerHTML = "Build: " + objSmtp.Build + 
                                                  "; Module: " + objSmtp.Module;

      var objForm = document.forms["SmtpSampleForm"];
      objForm.txtResult.value = "n/a";
      objForm.txtLogfile.value = fso.GetSpecialFolder(2) + "\\AxEmail.Smtp.log";

      var OptionHighest = document.createElement('option');
      var OptionHigh    = document.createElement('option');
      var OptionNormal  = document.createElement('option');
      var OptionLow     = document.createElement('option');
      var OptionLowest  = document.createElement('option');

      OptionHighest.text = "Highest Priority";
      OptionHigh.text    = "High Priority";
      OptionNormal.text  = "Normal Priority";
      OptionLow.text     = "Low Priority";
      OptionLowest.text  = "Lowest Priority";

      OptionHighest.value = objConstants.EMAIL_MESSAGE_PRIORITY_HIGHEST;
      OptionHigh.value    = objConstants.EMAIL_MESSAGE_PRIORITY_HIGH;
      OptionNormal.value  = objConstants.EMAIL_MESSAGE_PRIORITY_MEDIUM;
      OptionLow.value     = objConstants.EMAIL_MESSAGE_PRIORITY_LOW;
      OptionLowest.value  = objConstants.EMAIL_MESSAGE_PRIORITY_LOWEST;

      objForm.ddlPriority.add(OptionHighest);
      objForm.ddlPriority.add(OptionHigh);
      objForm.ddlPriority.add(OptionNormal);
      objForm.ddlPriority.add(OptionLow);
      objForm.ddlPriority.add(OptionLowest);
      objForm.ddlPriority.value = objConstants.EMAIL_MESSAGE_PRIORITY_MEDIUM;
    }
    
    function SendMessage() {
      var objEmail = new ActiveXObject("AxEmail.Message");
      var objForm = document.forms["SmtpSampleForm"];      

      objEmail.FromName = objForm.txtFromName.value;
      objEmail.FromAddress = objForm.txtFromAddress.value;
      
      if (objForm.txtToAddress.value != "")
      {
        objEmail.AddTo (objForm.txtToAddress.value,  objForm.txtToAddress.value);
      }
      
      if (objForm.txtCcAddress.value != "" && objEmail.LastError == 0)
      {
        objEmail.AddCc (objForm.txtCcAddress.value,  objForm.txtCcAddress.value);
      }
      
      if (objForm.txtBccAddress.value != "" && objEmail.LastError == 0)
      {
        objEmail.AddBcc(objForm.txtBccAddress.value, objForm.txtBccAddress.value);
      }
      
      if (objEmail.LastError == 0)
      {
        objEmail.Subject  = objForm.txtSubject.value;
        objEmail.Priority = objForm.ddlPriority.value;
        objEmail.Encoding = objForm.ddlEncoding.value;
        
        objEmail.BodyPlainText  = objForm.txtPlainBody.value;
        objEmail.BodyHtml       = objForm.txtHtmlBody.value;
        
        if (objForm.cbxSecure.checked == 1)
        objSmtp.SetSecure(465); // 465 is the generic secure SMTP port
      }
      
      if (objEmail.LastError == 0 && objSmtp.LastError == 0)
      {
        objSmtp.Connect(objForm.txtHost.value,objForm.txtAccount.value,objForm.txtPassword.value);
      }
      
      if (objEmail.LastError == 0 && objSmtp.LastError == 0)
      {
        objSmtp.Send(objEmail);
      }
      
      if (objEmail.LastError != 0)
      {
        objForm.txtResult.value = objEmail.LastError + ": " + 
          objEmail.GetErrorDescription(objEmail.LastError);
      }
      else
      {      
        objForm.txtResult.value = objSmtp.LastError + ": " + 
          objSmtp.GetErrorDescription(objSmtp.LastError);
      }     

      objSmtp.Disconnect();
      
    }    
  
  </script>
</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_menu">
      | <a href="index.html">Home</a>     
      | <a href="smtp.html">SMTP</a>
      | <a href="pop3.html">POP3</a> |
    </div><!-- /menu -->
    <div class="ax_container">
      <h1>Email Component Javascript 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.
      </p>
      <form name="SmtpSampleForm" action="smtp.html" method="post">
        <h2>Email Component:</h2>
        <h3 id="APIinfo"></h3>
        
        <!-- Server, Secure -->   
        <label for="Server">Mailserver:</label>
        <p>
          <input type="text" id="Server" name="txtHost" value="smtp.mycompany.com" />
          
          <input type="checkbox" class="ax_cbFix" id="Secure" name="cbxSecure" value="1" />
          <label for="Secure">Secure</label>
        </p>
        
        <!-- Account -->
        <label for="Account">Account*:</label>
        <p>
          <input type="text" id="Account" name="txtAccount" />
          *Only use when server requires authentication
        </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="SenderName">Sender name:</label>
        <p>
          <input type="text" id="SenderName" name="txtFromName" />
        </p>
        
        <!-- Sender Email --> 
        <label for="SenderEmail">Sender e-mail:</label>
        <p>
          <input type="text" id="SenderEmail" 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">
          </select>
        </p>
        
        <!-- SendButton -->
        <div class="ax_clearLabel"></div>
        <p>
          <input type="button" name="btnSendMessage" onclick="SendMessage()" 
            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" />
        </p>
        
        <!-- Logfile -->
        <label for="Logfile">Logfile:</label>
        <p>
          <input type="text" id="Logfile" name="txtLogfile" class="ax_FullWidth" />
        </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="index.html">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.