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 Microsoft Visual Studio .NET environments. This document describes how ActiveEmail can be integrated into Microsoft ASP .NET CSharp projects.
You must install and configre Internet Information Services (IIS) before using ActiveEmail with ASP .NET
If you don't have IIS installed, use the following stpes:
(Click on the picture to enlarge)
Download the ActiveEmail SMTP/POP3 Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Launch Microsoft Visual Studio (for instance 'Microsoft Visual Studio 2005') 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 (for instance: 'DemoApp') and a name for the solution (for instance: 'DemoSolution'). Also, select the directory where you want to store the project (for instance: 'C:\MyProjects):
(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 objects.
To do so, choose 'Add Reference...' from the 'Website' menu.
In the 'Add Reference' dialog that pops up, select the 'COM' tab and select the 'ActiveEmail 3.0 Type Library' as shown in the following picture:
(Click on the picture to enlarge)
Click 'OK' to close the 'Add Reference' dialog.
On top of your code, type the following line to use the ActiveEmail namespace:
using AEMAILLib;
In your Main function, declare and create the following objects for SMTP:
SmtpServer objSmtpServer = new SmtpServer(); SmtpMail objSmtpServer = new SmtpMail();
To use POP3, declare and create the following objects:
SmtpServer objPop3Server = new Pop3Server(); Pop3Mail objPop3Mail; // NOTE: do NOT create the Pop3Mail object, because it is created by the // Pop3Server object when a new message is received
To make use of ActiveEmail's constants, declare the EmailConstants object:
EmailConstants objConstants = new EmailConstants();
You can now send and/or receive e-mail messages.
The following code shows how to send an e-mail message:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AEMAILLib;
namespace SmtpDemo
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label labelServer;
protected System.Web.UI.WebControls.TextBox textServer;
protected System.Web.UI.WebControls.Label labelFromAddress;
protected System.Web.UI.WebControls.TextBox textFromAddress;
protected System.Web.UI.WebControls.Label labelFromName;
protected System.Web.UI.WebControls.TextBox textFromName;
protected System.Web.UI.WebControls.Label LabelMailTo;
protected System.Web.UI.WebControls.TextBox textMailTo;
protected System.Web.UI.WebControls.Label labelSubject;
protected System.Web.UI.WebControls.TextBox textSubject;
protected System.Web.UI.WebControls.Label labelBody;
protected System.Web.UI.WebControls.TextBox textBody;
protected System.Web.UI.WebControls.Label labelResult;
protected System.Web.UI.WebControls.TextBox textResult;
protected System.Web.UI.WebControls.Label labelResponse;
protected System.Web.UI.WebControls.TextBox textResponse;
protected System.Web.UI.WebControls.Button buttonSend;
private SmtpServer objSmtpServer;
private SmtpMail objSmtpMail;
private EmailConstants objConstants;
private void Page_Load(object sender, System.EventArgs e)
{
objSmtpServer = new SmtpServer();
objSmtpMail = new SmtpMail();
objConstants = new EmailConstants();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.buttonSend.Click += new System.EventHandler(this.buttonSend_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void buttonSend_Click(object sender, System.EventArgs e)
{
objSmtpServer.LogFile = "C:\\AspNetSmtpLog.txt";
objSmtpServer.Connect(textServer.Text, "", "");
if ( GetResult() == 0 )
{
objSmtpMail.FromAddress = textFromAddress.Text;
objSmtpMail.FromName = textFromName.Text;
objSmtpMail.AddTo( textMailTo.Text, "");
objSmtpMail.Subject = textSubject.Text;
objSmtpMail.Body = textBody.Text;
objSmtpMail.BodyType = objConstants.asMESSAGE_BODY_PLAIN;
objSmtpMail.Encoding = objConstants.asMESSAGE_ENCODING_DEFAULT;
objSmtpMail.Priority = objConstants.asMESSAGE_PRIORITY_HIGH;
object obj = objSmtpMail;
objSmtpServer.Send (ref obj );
GetResult();
}
}
private long GetResult()
{
long lResult = objSmtpServer.LastError;
textResponse.Text = objSmtpServer.LastSmtpResponse;
textResult.Text = "ERROR "
+ objSmtpServer.LastError.ToString() + " : "
+ objSmtpServer.GetErrorDescription(objSmtpServer.LastError);
return lResult;
}
}
}
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.
The ActiveEmail project ships with a set of Microsoft Visual Studio .NET samples, including samples for Microsoft ASP .NET C#. The projects are created with Microsoft Visual Studio 2005.
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.