ActiveXperts Email Component

Quicklinks

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).


Introduction

In this example we are going to create a Visual Basic Script page to send E-mail messages. This demo project will ask the user to give an e-mail address and a message body on the command prompt.

Step 1: Download and install ActiveXperts Email Component

Download ActiveXperts Email Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

Step 3: Create ActiveXperts Email Component objects in VBScript

The following code will show you how to declare and create the SMTP and E-mail objects. We will use the 'objSmtp' object to send the message itself. The 'objSmtpMail' object will be used to store information of the message and the 'objConstants' object containes constant values releated to the e-mail objects.

Dim objSmtp, objMail, objConstants
Dim strSmtpServer, strSmtpAccount, strSmtpPassword
Dim strRecipient, strAttachment

Set objSmtp              = CreateObject("AxEmail.Smtp")
Set objMail              = CreateObject("AxEmail.Message")
Set objConstants         = CreateObject("AxEmail.Constants")

Step 4: Gather information

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.

' Mail: Clear (good practise)
objMail.Clear()

' Mail: From
' Some mail servers (including MS Exchange) require an existing mail address on that server
objMail.FromAddress   = ReadInput( "FromAddress:", "me@mydomain.local", False )      
  
' Mail: Subject  
objMail.Subject       = ReadInput( "Subject:", "ActiveXperts Test Message", False )
  
' Mail: Body
objMail.BodyPlainText = ReadInput( "Message (Plain Text):", "Hello, world!", False)
objMail.BodyHtml      = ReadInput( "Message (Html):", "Hello, world!", False)

' Mail: Priority
objMail.Priority      = objConstants.EMAIL_MESSAGE_PRIORITY_MEDIUM  ' Normal (default) priority
  
' Mail: To  
strRecipient = ReadInput( "ToAddress:", "you@yourdomain.local", False )
objMail.AddTo strRecipient, strRecipient    
WScript.Echo "AddTo, result: " & objMail.LastError
If( objMail.LastError <> 0 ) Then
  WScript.Quit
End If

' Mail: Cc
strRecipient = ReadInput( "CcAddress (optional):", "", True )
If( strRecipient <> "" ) Then 
  objMail.AddCc strRecipient, strRecipient  
  WScript.Echo "AddCc, result: " & objMail.LastError
End If 
If( objMail.LastError <> 0 ) Then
  WScript.Quit
End If  

' Mail: Attachment
strAttachment = ReadInput( "Attachment (optional):", "", True )
If( strAttachment <> "" ) Then 
  objMail.AddAttachment strAttachment  
  WScript.Echo "AddAttachment, result: " & objMail.LastError
End If
If( objMail.LastError <> 0 ) Then
  WScript.Quit
End If

Step 4: Send E-mail messages

You can now send E-mail messages.

The following VBScript code shows how to send e-mail messages through SMTP:

' Smtp: Send
objSmtp.Send ( objMail )
WScript.Echo "Send, result: " & objSmtp.LastError
WScript.Echo "Last response from SMTP Server: " & objSmtp.LastSmtpResponse 

Appendix: Full source code

Following you can find the full source code which is also included in ActiveXperts Email Component package.

' ********************************************************************
'
' ActiveXperts Email Component
'
' Send a simple e-mail
'
' (c) Copyright ActiveXperts Software - www.activexperts.com
'
' ********************************************************************


Option Explicit

Dim objSmtp, objMail, objConstants
Dim strSmtpServer, strSmtpAccount, strSmtpPassword
Dim strRecipient, strAttachment

Set objSmtp              = CreateObject("AxEmail.Smtp")
Set objMail              = CreateObject("AxEmail.Message")
Set objConstants         = CreateObject("AxEmail.Constants")

' Display Email Component Version
WScript.Echo "Email Component Version " & objSmtp.Version & "; " & _
                                   "Build " & objSmtp.Build & "; " & _
                                  "Module " & objSmtp.Module

' Display if ActiveXperts Email Component is registered.
WScript.Echo "License Status: " & objSmtp.LicenseStatus & vbCrLf 

' Mail: Clear (good practise)
objMail.Clear()

' Mail: From
' Some mail servers (including MS Exchange) require an existing mail address on that server
objMail.FromAddress   = ReadInput( "FromAddress:", "me@mydomain.local", False )      
  
' Mail: Subject  
objMail.Subject       = ReadInput( "Subject:", "ActiveXperts Test Message", False )
  
' Mail: Body
objMail.BodyPlainText = ReadInput( "Message (Plain Text):", "Hello, world!", False)
objMail.BodyHtml      = ReadInput( "Message (Html):", "Hello, world!", False)

' Mail: Priority
objMail.Priority      = objConstants.EMAIL_MESSAGE_PRIORITY_MEDIUM  ' Normal (default) priority
  
' Mail: To  
strRecipient = ReadInput( "ToAddress:", "you@yourdomain.local", False )
objMail.AddTo strRecipient, strRecipient    
WScript.Echo "AddTo, result: " & objMail.LastError
If( objMail.LastError <> 0 ) Then
  WScript.Quit
End If

' Mail: Cc
strRecipient = ReadInput( "CcAddress (optional):", "", True )
If( strRecipient <> "" ) Then 
  objMail.AddCc strRecipient, strRecipient  
  WScript.Echo "AddCc, result: " & objMail.LastError
End If 
If( objMail.LastError <> 0 ) Then
  WScript.Quit
End If  

' Mail: Attachment
strAttachment = ReadInput( "Attachment (optional):", "", True )
If( strAttachment <> "" ) Then 
  objMail.AddAttachment strAttachment  
  WScript.Echo "AddAttachment, result: " & objMail.LastError
End If
If( objMail.LastError <> 0 ) Then
  WScript.Quit
End If    

' Smtp: Clear (good practise)
objSmtp.Clear()

' Smtp: Logfile
Dim fso: Set fso               = CreateObject("Scripting.FileSystemObject")
objSmtp.LogFile                = fso.GetSpecialFolder(2) & "\SMTP_SendMail.txt"
WScript.Echo "Log file can be found here:"
Wscript.Echo objSmtp.LogFile

' Smtp: Server, Account, Password
strSmtpServer = ReadInput( "Mail server:", "smtp.gmail.com", False )
strSmtpAccount = ReadInput( "Login (optional):", "", True )
If( strSmtpAccount <> "" ) Then
  strSmtpPassword = ReadInput( "Password:", "", True )
End If

' Smtp: Set secure if mail server is a secure (TLS/SSL) mailserver)
If( LCase( strSmtpServer ) = "smtp.gmail.com" ) Then
  objSmtp.SetSecure 465
  WScript.Echo "SetSecure, result: " & objSmtp.LastError
End If
If( objSmtp.LastError <> 0 ) Then
  WScript.Quit
End If

' Smtp: Connect
objSmtp.Connect strSmtpServer, strSmtpAccount, strSmtpPassword  
Wscript.Echo "Connect, result: " & objSmtp.LastError
If( objSmtp.LastError <> 0 ) Then
    WScript.Quit
End If

' Smtp: Send
objSmtp.Send ( objMail )
WScript.Echo "Send, result: " & objSmtp.LastError
WScript.Echo "Last response from SMTP Server: " & objSmtp.LastSmtpResponse 
 

' Smtp: Disconnect
objSmtp.Disconnect
WScript.Echo "Disconnected."

WScript.Echo "Ready."


' *************************************************************************************

Function ReadInput( ByVal strTitle, ByVal strDefault, ByVal bAllowEmpty )

  Dim strInput, strReturn

  Do
     strInput = inputbox( strTitle, "Enter value", strDefault )
     If ( strInput <> "" ) Then
          strReturn = strInput
     End If
  Loop until strReturn <> "" Or bAllowEmpty

  ReadInput = strReturn
End Function

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 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.