ActiveEmail

 Product Overview

 How to use

 Online Samples

 Download (.exe)

 Brochure (.pdf)

 Manual (.htm)

 Release Notes


Support

 Knowledge Base

 Forum

 Contact Support


Purchase

 Licensing

 Pricing

 Order now


Related documents

 E-mail headers

 MIME encoding

 MIME and ActiveEmail

 SMTP via Telnet

 POP3 via Telnet

 RFC's supported:
 RFC 821,  RFC 822
 RFC 1521,  RFC 1522,
 RFC 2104,  RFC 2195,
 RFC 2449,  RFC 2554,
 RFC 2595,  more...


  Download ActiveEmail SMTP/POP3 Toolkit 3.0  (4433 KB - .exe file)
  Download Manual  (190 KB - .htm file)


Using ActiveEmail SMTP/POP3 Toolkit with Visual C++ 5.x/6.x


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 and many more), different encodings (including 7/8 bit, quoted-printable, base64).

ActiveEmail can be well integrated into Visual C++ environments. This document describes how ActiveEmail can be integrated into Visual Studio C++ 5.x/6.x projects.


Step 1: Download and install ActiveEmail

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



Step 2: Create a new Visual C++ project

Launch 'Microsoft Visual C++' from the Start menu, and choose 'New' from the 'File Menu'. The 'New' dialog appears.
Select the type of project (for instance: 'Win32 Console Application'), enter a 'Project name' and select the 'Location':

    
    (Click on the picture to enlarge)

Select the kind of project, for instance a 'Hello, world!' application and click 'Finish':

    
    (Click on the picture to enlarge)



Step 3: Refer to the ActiveEmail Library and declare the objects

A new Project is created now.

Before you can use ActiveEmail, you need to refer to the ActiveEmail library. The actually reference files are shipped with the product and are located in the following directory:
    C:\Program Files\ActiveXperts\ActiveEmail\Examples\Visual C++\Include
Copy all files in the above directory ('AEmail.h', 'AEmail_i.c' and 'AEmailConstants.h') to your project directory.

On top of your code, declare the following objects for SMTP:
    ISmtpServer *pSmtpServer    = NULL;
    ISmtpMail   *pSmtpMail      = NULL;
and/or declare the following objects for POP3:
    IPop3Server *pPop3Server    = NULL;
    IPop3Mail   *pPop3Mail      = NULL;


Step 4: Create the objects

Since ActiveEmail is a COM object, you must initialize the COM library before they can call COM library functions (e.g. ActiveEmail functions):
   CoInitialize(NULL);
Create the SMTP objects in the following way:
   CoCreateInstance( CLSID_SmtpServer, NULL, CLSCTX_INPROC_SERVER, IID_ISmtpServer, (void**) &pSmtpServer);
   CoCreateInstance( CLSID_SmtpMail, NULL, CLSCTX_INPROC_SERVER, IID_ISmtpMail, (void**) &pSmtpMail )
Create the POP3 objects in the following way:
   CoCreateInstance( CLSID_Pop3Server, NULL, CLSCTX_INPROC_SERVER, IID_IPop3Server, (void**) &pPop3Server);
   // NOTE: do NOT create the Pop3Mail object, because it is created by the Pop3Server object when a new message is received


Step 5: Send and/or receive an e-mail messages

You can now send and/or receive e-mail messages.

The following code shows how to send an e-mail message:
   #include <comdef.h>
   #include <atlbase.h>
   #include <windows.h>
   #include <stdio.h>

   ////////////////////////////////////////////////////////////////////////////////

   #include "..\include\aemail.h"
   #include "..\include\aemail_i.c"
   #include "..\include\aemailconstants.h"

   ////////////////////////////////////////////////////////////////////////////////

   int main(int argc, char* argv[])
   {
      ISmtpMail    *pSmtpMail              = NULL;
      ISmtpServer  *pSmtpServer            = NULL;

      LONG         lLastError          = 0L;
      HRESULT      hr;

      _bstr_t      bstrHostName        = "smtp.mydomain.com";
      _bstr_t      bstrFromAddress     = "me@mydomain.dom";
      _bstr_t      bstrFromName        = "The Sender";
      _bstr_t      bstrRecipientAddress  = "me@therecipient.com";
      _bstr_t      bstrRecipientName   = "You";
      _bstr_t      bstrSubject         = "This is the Subject";
      _bstr_t      bstrMessage         = "This is the body of the e-mail message. It's just a simple e-mail (no RTF, attachments etc).";
   
      BSTR         pErrorDescription   = NULL;

      VARIANT      vtMail;

      // initialize COM
      CoInitialize(NULL);

      hr = CoCreateInstance(CLSID_SmtpServer, NULL, CLSCTX_INPROC_SERVER, IID_ISmtpServer, (void**) &pSmtpServer);
      if( ! SUCCEEDED( hr ) )
      {
          pSmtpServer = NULL;
          printf( "Unable to create instance of the object.\n" );
          goto _EndMain;
      }

      hr = CoCreateInstance(CLSID_SmtpMail, NULL, CLSCTX_INPROC_SERVER, IID_ISmtpMail, (void**) &pSmtpMail);
      if( ! SUCCEEDED( hr ) )
      {
          pSmtpMail = NULL;
          printf( "Unable to create instance of the object.\n" );
          goto _EndMain;
      }

      printf( "Connecting...\n" );
      pSmtpServer->Connect( bstrHostName, _bstr_t(""), _bstr_t("") );
      pSmtpServer->get_LastError ( &lLastError );
      pSmtpServer->GetErrorDescription( lLastError, &pErrorDescription );
      printf( "Connect, result: %ld (%ls)\n", lLastError, pErrorDescription ); 

      if( lLastError != 0L )
         goto _EndMain;

      pSmtpMail->put_FromAddress( bstrFromAddress );
      pSmtpMail->put_FromName( bstrFromName );
      pSmtpMail->put_Subject( bstrSubject );
      pSmtpMail->put_Body( bstrMessage );
      pSmtpMail->put_BodyType( asMESSAGE_BODY_PLAIN );         // Plain text (default)
      pSmtpMail->put_Priority( asMESSAGE_PRIORITY_MEDIUM );    // Normal priority (default)
      pSmtpMail->put_Encoding( asMESSAGE_ENCODING_DEFAULT );   // Default Encoding
      pSmtpMail->AddTo( bstrRecipientAddress, bstrRecipientName );

      printf( "Sending...\n" );
	
      VariantInit ( &vtMail );
      vtMail.pdispVal = pSmtpMail;
      vtMail.vt = VT_DISPATCH;
      pSmtpServer->Send ( &vtMail );
      pSmtpServer->get_LastError( &lLastError );
      pSmtpServer->GetErrorDescription( lLastError, &pErrorDescription );
      printf( "Send, result: %ld (%ls)\n", lLastError, pErrorDescription );

      printf( "Disconnecting...\n" );
      pSmtpServer->Disconnect();

_EndMain:

   if( pErrorDescription != NULL )
      SysFreeString( pErrorDescription );

   if( pSmtpServer != NULL )   pSmtpServer->Release();
   if( pSmtpMail != NULL )     pSmtpMail->Release ();

   printf( "Ready.\n" );

   return lLastError;
}
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/activemail.





ActiveEmail is a SMTP- and POP3 development component (SDK). This control can be used by any Windows development platform, including Visual Basic .NET, Visual CSharp .NET, ASP .NET (VB,CS), ASP, Visual Basic, Visual Studio/Visual C++, Delphi, PHP, HTML, VBScript and any other ActiveX/COM compliant platform. ActiveEmail is an ActiveXperts Software B.V. Product.

Copyright ©1999-2007 ActiveXperts Software. All rights reserved.