smtp-pop3-component SMTP/POP3 Toolkit Add SMTP/POP3 capabilities to any Windows or .NET application

Quicklinks


ActiveEmail SMTP/POP3 Toolkit is a software development kit (SDK) that enables the user to send (SMTP) and receive (POP3) e-mail messages. ActiveEmail 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 use create a ColdFusion project to receive e-mail messages through POP3. This demo project will ask the user to give the user's e-mail address and a password in the web interface.

Step 1: Download and install the ActiveEmail Toolkit

Download the ActiveEmail Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new ColdFusion document

Create a new blank webdocument with the ".cfm" extention. First of all we are going to build the form whitch commands and properties of the device can be filled in. Then we are going to make a source code that connects to the device.

Step 3: Declare and create the ActiveEmail Toolkit objects

The following code will show you how to declare and create the POP3 and E-mail objects. We will use the 'objPop3' object to send the message itself. The 'objEmail' object will be used to store information of the message and the 'objEmailConstants' object containes constant values releated to the SMS objects. .

<cfobject type="com" Action="Create" class="ActiveEmail.Pop3"           name="objPop3">
<cfobject type="com" Action="Create" class="ActiveEmail.EmailConstants" name="objEmailConstants">
<cfobject type="com" Action="Create" class="ActiveEmail.EmailMessage"   name="objEmail">

Step 4: Create a ColdFusion webform.

The following information is required to receive an e-mail message:

  • The recipient's e-mail address.
  • The message.

Create a simple form to collect this information from the user. You can configure the required fields as required fields in ColdFusion. If the user does not fill in these fields properly, a messagebox is shown and the form will not be submitted. Make sure you create a ColdFusion form, not a plain HTML form.

A ColdFusion form which collects this information might look like this:

Step 5: Receive e-mail messages

The following code will download all the messages from the POP3 server and add them to an array of messages:

if (objPop3.LastError == 0)
{
  for (i = 1; i LTE numMessages; i++)
  {
    objEmail = objPop3.GetEmailHeader(i);
    strResult = objPop3.LastError & ': ' & objPop3.GetErrorDescription(objPop3.LastError);
    
    if (objPop3.LastError == 0)
    {          
      ArrayAppend(arrMails, objEmail);
    }
  }
}

Appendix: Full source code

Following you can find the full source code which is also included in the ActiveEmail Toolkit package.

<cfobject type="com" Action="Create" class="ActiveEmail.Pop3"           name="objPop3">
<cfobject type="com" Action="Create" class="ActiveEmail.EmailConstants" name="objEmailConstants">
<cfobject type="com" Action="Create" class="ActiveEmail.EmailMessage"   name="objEmail">

<cfscript>
  arrMails = ArrayNew(1);
  strResult = "n/a";
  objPop3.LogFile = "C:\Windows\Windows\Temp\ActiveXperts.Pop3.log";
  
  if (IsDefined("Form.btnListMessages"))
  {
    objPop3.Authentication = objEmailConstants.POP3_AUTH_AUTO;
    
    if (IsDefined("Form.cbxSecure"))
    {
      objPop3.SetSecure(995);
    }
    
    if (objPop3.LastError == 0)
    {
      objPop3.Connect(Form.txtHost, Form.txtAccount, Form.txtPassword);
      strResult = objPop3.LastError & ': ' & objPop3.GetErrorDescription(objPop3.LastError);
    }
    
    if (objPop3.LastError == 0)
    {
      numMessages = objPop3.CountMessages();
      strResult = objPop3.LastError & ': ' & objPop3.GetErrorDescription(objPop3.LastError);
    
      if (objPop3.LastError == 0)
      {
        for (i = 1; i LTE numMessages; i++)
        {
          objEmail = objPop3.GetEmailHeader(i);
          strResult = objPop3.LastError & ': ' & objPop3.GetErrorDescription(objPop3.LastError);
          
          if (objPop3.LastError == 0)
          {          
            ArrayAppend(arrMails, objEmail);
          }
        }
      }
    }
  }
</cfscript>

<!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 Mobile Messaging Toolkit Demo</title>
  <link rel="Stylesheet" type="text/css" href="css/Layout.css" />
</head>
<body>
  <div class="maincontainer">
    <div class="header">
      <div class="stroke"></div>
      <div class="logo"></div>
    </div><!-- /header -->

    <div class="container">
      <h1>ActiveEmail Toolkit Coldfusion POP3 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 action="pop3.cfm" method="post">
      <cfoutput>
        <h2>ActiveEmail Toolkit:</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" />
          
          <input type="checkbox" class="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" value="user@mycompany.com" />
        </p>
        
        <!-- Password -->
        <label for="Password">Password:</label>
        <p>
          <input type="password" id="Password" name="txtPassword" value="" />
        </p>
        
        <!-- Empty row -->
        <div class="clearRow"></div>
        
        <!-- List Messages button -->
        <div class="clearLabel"></div>
        <p>
          <input type="submit" name="btnListMessages" value="List Messages" />
        </p>
        
        <!-- Messages Listbox -->
        <label for="Received">Messages received:</label>
        <p>
          <select id="Received" name="lvMessages" size="10">
          <cfloop array=#arrMails# index="Mail">
            <cfoutput>
              <option>#Mail.Date#: #Mail.FromAddress#; Subject #Mail.Subject#</option>
            </cfoutput>
          </cfloop>
          </select>
        </p>
        
        <!-- Result -->
        <label for="Result" class="Bold">Result:</label>
        <p>
          <input type="text" id="Result" name="txtResult" class="FullWidth Bold" class="FullWidth" 
              value="#strResult#" />
        </p>
      </cfoutput>
      </form>
      <p>
        This demo uses the ActiveXperts ActiveEmail Toolkit, an 
        <a href="http://www.activexperts.com" target="_blank">ActiveXperts Software</a> product.
        <br />
        <a href="index.cfm">Back to main page</a>
      </p>
    </div><!-- /container -->
    <div class="footer">
      <div class="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 ActiveEmail Toolkit 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.