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 and many more), different encodings (including 7/8 bit, quoted-printable, base64).
ActiveEmail can be well integrated into Borland C++ Builder environments. This document describes how ActiveEmail can be integrated into Borland C++ Builder projects.
Download the ActiveEmail SMTP/POP3 Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Borland C++ Builder (for instance 'Borland C++ Builder 6') from the Start menu. Choose 'New' from the 'File' menu and select 'Application'. A new Form is displayed in the workspace.
(Click on the picture to enlarge)
Now that a new project has been created, you must add a reference to ActiveEmail in the project to be able to use the ActiveEmail object. To do so, choose 'Import Type Library...' from the 'Project' menu. The Import Type Library' dialog appears.
(Click on the picture to enlarge)
In the upper selection box, select 'ActiveEmail 3.1 Type Library' and click 'Create Unit':
The interface code is generated now and is shown in the AEMAILLib_TLB.cpp and AEMAILLib_TLB.h tab of the project.
From the Project Manager, open Unit1.h and add include the AEMAILLib_TLB.h file to refer to the ActiveEmail library:
(Click on the picture to enlarge)
In the 'private' or 'public' section, declare the following objects:
TCOMISmtpServer m_objSmtpServer; TCOMISmtpMail m_objSmtpMail;
You can now create the objects, for instance in the 'FormCreate' event handler or the class constructor:
m_objSmtpServer = CoSmtpServer::Create (); m_objSmtpMail = CoSmtpMail::Create ();
You can now send email messages using a SMTP server.
The following code shows how to send an email:
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop //--------------------------------------------------------------------------- #include "UnitSmtp.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" //--------------------------------------------------------------------------- TFormSmtp *FormSmtp; //--------------------------------------------------------------------------- __fastcall TFormSmtp::TFormSmtp(TComponent* Owner) : TForm(Owner) { m_objSmtpServer = CoSmtpServer::Create (); m_objSmtpMail = CoSmtpMail::Create (); } //--------------------------------------------------------------------------- void __fastcall TFormSmtp::FormCreate(TObject *Sender) { CHAR szTemp [ MAX_PATH + 1 ]; GetTempPath ( MAX_PATH, szTemp ); strcat ( szTemp, "HttpPost.log" ); EditLogfile->Text = szTemp; CheckAuthenticationClick ( this ); } //--------------------------------------------------------------------------- void __fastcall TFormSmtp::ButtonSendClick(TObject *Sender) { // Clear all properties m_objSmtpServer->Clear (); // Set Logfile m_objSmtpServer->set_LogFile(WideString (EditLogfile->Text)); // Connect to SMTP Server if ( CheckAuthentication->Checked == true ) { m_objSmtpServer->Connect(WideString(EditHost->Text ), WideString (EditAccount->Text), WideString (EditPassword->Text)); } else { m_objSmtpServer->Connect(WideString(EditHost->Text ), WideString (""), WideString ("")); } if ( GetResult () == 0 ) { // Clear Email m_objSmtpMail->Clear(); // Set Recipients m_objSmtpMail->AddTo( WideString (EditRecipientMail->Text), WideString (EditRecipientName->Text)); // Set Sender m_objSmtpMail->set_FromAddress(WideString(EditSenderMail->Text)); m_objSmtpMail->set_FromName (WideString(EditSenderName->Text )); // Set Subject m_objSmtpMail->set_Subject(WideString(EditSubject->Text)); // Set Body m_objSmtpMail->set_Body(WideString(EditBody->Text)); // Set Attachment(s) m_objSmtpMail->AddAttachment(WideString(EditAttachment->Text)); // Send Message Variant vtVarMessage ( ( IDispatch* ) m_objSmtpMail ); m_objSmtpServer->Send( ( VARIANT * ) vtVarMessage ); GetResult (); } } //--------------------------------------------------------------------------- long TFormSmtp::GetResult () { long lResult = m_objSmtpServer->LastError; EditResult->Text = IntToStr ( lResult ) + " : " + m_objSmtpServer->GetErrorDescription(lResult); EditLastResponse->Text = m_objSmtpServer->LastSmtpResponse; return lResult; } //--------------------------------------------------------------------------- void __fastcall TFormSmtp::ButtonBrowseClick(TObject *Sender) { if ( OpenDialog->Execute() == TRUE ) { EditAttachment->Text = OpenDialog->FileName; } } //--------------------------------------------------------------------------- void __fastcall TFormSmtp::ButtonViewClick(TObject *Sender) { if ( EditLogfile->Text.Length() ) { ShellExecute ( NULL, _T("open"), EditLogfile->Text.c_str(), NULL, NULL, SW_SHOWDEFAULT ); } } //--------------------------------------------------------------------------- void __fastcall TFormSmtp::CheckAuthenticationClick(TObject *Sender) { if ( CheckAuthentication->Checked == true ) { EditAccount->Enabled = true; EditPassword->Enabled = true; } else { EditAccount->Enabled = false; EditPassword->Enabled = false; } } //---------------------------------------------------------------------------
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/aemail.
The ActiveEmail project ships with a set of samples for Borland C++ Builder. The projects are created with Borland C++ Builder 6.
Users with a later version of Borland C++ Builder 6 can open such a project. The Borland Conversion Wizard will guide you through the process of converting the project to the version used.