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).
In this example we are going to use Visual Studio 2008 to create an ASP.NET VB console application project named 'DemoApp' in a solution named 'DemoSolution'. We are going to store this project in the directory 'C:\MyProjects'. All of these names can be changed according to your preferences. This demo project will ask the user to give an e-mail address and a message body on the command prompt.
You must install and configure Internet Information Services (IIS) before using ActiveXperts Email Component with ASP .NET If you don't have IIS installed, use the following stpes:
Download ActiveXperts Email Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Microsoft Visual Studio from the Start menu. Choose 'New' from the 'File' menu and click on 'Web Site'. In the 'Web Site' dialog, select ASP .NET Web Site. Select a name for the application and a name for the solution. Also, select the directory where you want to store the project:
Now that a new project has been created, you must add a reference to ActiveXperts Email Component in the project to be able to use ActiveXperts Email Component objects. To do so, choose 'Add Reference...' from the 'Project' menu. In the 'Add Reference' dialog that pops up, select the 'COM' tab and select ActiveXperts Email Component Type Library' as shown in the following picture:
Click 'OK' to close the 'Add Reference' dialog.
On top of your code, type the following line to use ActiveXperts Email Component namespace:
Imports AxEmail Imports System.IO Partial Public Class frmsmtp Inherits System.Web.UI.Page Private objSmtp As Smtp = New Smtp Private objEmail As EMailMessage = New Message Private objEmailConstants As EMailConstants = New Constants
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. You can also specify the priority of an e-mail.
' Mail: Clear objEmail.Clear() ' Mail: From objEmail.FromName = txtFromName.Text objEmail.FromAddress = txtFromAddress.Text ' Mail: Encoding If (ddlEncoding.SelectedIndex = 0) Then objEmail.Encoding = objEmailConstants.EMAIL_MESSAGE_ENCODING_DEFAULT Else objEmail.Encoding = objEmailConstants.EMAIL_MESSAGE_ENCODING_UTF8 End If ' Mail: Priority objEmail.Priority = ddlPriority.SelectedIndex Select Case ddlPriority.SelectedValue Case "Highest Priority" objEmail.Priority = objEmailConstants.EMAIL_MESSAGE_PRIORITY_HIGHEST Case "High Priority" objEmail.Priority = objEmailConstants.EMAIL_MESSAGE_PRIORITY_HIGH Case "Normal Priority" objEmail.Priority = objEmailConstants.EMAIL_MESSAGE_PRIORITY_MEDIUM Case "Low Priority" objEmail.Priority = objEmailConstants.EMAIL_MESSAGE_PRIORITY_LOW Case "Lowest Priority" objEmail.Priority = objEmailConstants.EMAIL_MESSAGE_PRIORITY_LOWEST End Select ' Mail: Subject objEmail.Subject = txtSubject.Text ' Mail: Body objEmail.BodyPlainText = txtPlainBody.Text objEmail.BodyHtml = txtHtmlBody.Text ' Mail: Add TO recipient(s) If (txtToAddress.Text <> String.Empty) Then objEmail.AddTo(txtToAddress.Text, txtToAddress.Text) End If ' Mail: Add CC recipient(s) If (objEmail.LastError = 0 And txtCcAddress.Text <> String.Empty) Then objEmail.AddCc(txtCcAddress.Text, txtCcAddress.Text) End If ' Mail: Add BCC recipient(s) If (objEmail.LastError = 0 And txtBccAddress.Text <> String.Empty) Then objEmail.AddBcc(txtBccAddress.Text, txtBccAddress.Text) End If ' Mail: On error return If (objEmail.LastError <> 0) Then txtResult.Text = objEmail.LastError & ": " * objEmail.GetErrorDescription(objEmail.LastError) Exit Sub End If ' Smtp: Clear (good practise) objSmtp.Clear()
You can now send E-mail messages.
The following code shows how to send an E-mail message through SMTP:
' Smtp: Send If (objSmtp.LastError = 0) Then objSmtp.Send(objEmail) End If
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.
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.