ActivEmail SMTP/POP3 Toolkit Add SMTP/POP3 capabilities to any Windows or .NET application

Quicklinks


Using ActiveEmail SMTP/POP3 Toolkit using VBScript

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 VBScript environments. This document describes how ActiveEmail can be usied with VBScript.

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

You're now able to write a more advanced ASP script to send/receive e-mail using ActiveEmail.

Step 3: Create the ActiveEmail objects in VBScript

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:

Option Explicit
This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.

Now, declare the ActiveEmail SMTP objects:
Dim objSmtpServer
Dim objSmtpMail
Dim objConstants

Create the SMTP objects like this:

Set objSmtpServer = CreateObject( "ActiveXperts.SmtpServer" )
Set objSmtpMail   = CreateObject( "ActiveXperts.SmtpMail" )
Set objConstants  = CreateObject( "ActiveXperts.EMailConstants" )

Similary, you can declare and create the POP3 objects:

Dim objPop3Server
Dim objPop3Mail
   
Set objPop3Server = CreateObject( "ActiveXperts.Pop3Server" )
' NOTE: do NOT create the Pop3Mail object, because it 
' is created by the Pop3Server object when a new message is received

Now, add the following lines to the file to have your fist ActiveEmail VBScript program:

WScript.Echo "Version: " & objSmtpServer.Version
WScript.Echo "Expiration Date: " & objSmtpServer.Expiration Date

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

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

The following VBScript code shows how to send an e-mail:

Option Explicit
   
Dim objSmtpServer, objSmtpMail, objConstants
   
Set objSmtpServer        = CreateObject("ActiveXperts.SmtpServer")
Set objSmtpMail          = CreateObject("ActiveXperts.SmtpMail")
Set objConstants         = CreateObject("ActiveXperts.EMailConstants")
   
Wscript.Echo "ActiveEmail " & objSmtpServer.Version & " demo."
Wscript.Echo "Expiration date: " & objSmtpServer.ExpirationDate & vbCrLf
   
' For troubleshooting, specify a log file
' objSmtpServer.LogFile  = "C:\ActiveEmail.log"
   
' Connect to SMTP mailserver
' If server credentails are required, pass Account name and Password as additional parameters
' If port other than default port 25 is required, set the HostPort property first

   
objSmtpServer.Connect( "smtp.mydomain.com" )  
Wscript.Echo "Connect, result: " & objSmtpServer.LastError
If( objSmtpServer.LastError <> 0 ) Then
	WScript.Quit
End If
   
' = Set mail properties =

' Some mail servers (including MS Exchange) require an existing mail address on that server
objSmtpMail.FromAddress  = "sender@mydomain.com"                   
' Displayname
objSmtpMail.FromName     = "ActiveEmail Demo"                      
objSmtpMail.Subject      = "ActiveEmail Message"
' Normal (default) priority
objSmtpMail.Priority     = objConstants.asMESSAGE_PRIORITY_MEDIUM 
' Plain body format (no RTF/HTML format)
objSmtpMail.BodyType     = objConstants.asMESSAGE_BODY_PLAIN       
objSmtpMail.Body         = "Hello my friend," & vbCrLf & _
                           "How are you?" & vbCrLf & "Regards."
' Call this function to add recipients
objSmtpMail.AddTo "recipient1@myrecipients.com", "Recipient 1"     
' Call this function to add CC recipients
objSmtpMail.AddCc "recipient2@myrecipients.com", "Recipient 2"     
   
' Send mail now
objSmtpServer.Send( objSmtpMail )
WScript.Echo "Send, result: " & objSmtpServer.LastError
If( objSmtpServer.LastSmtpResponse <> "" ) Then
	WScript.Echo "Last response from SMTP Server: " & objSmtpServer.LastSmtpResponse 
End If  
   
' Disconnect
objSmtpServer.Disconnect
WScript.Echo "Disconnected."
   
WScript.Echo "Ready."

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.