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, hebrew and many more), different encodings (including 7/8 bit, quoted-printable, base64).
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 the username and password needed to connect to the POP3 server.
Download the ActiveEmail Toolkit from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
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.
Create a new VBScript file called Demo.vbs.
In the following code we will create the 'objPop3' object which will store the information of the POP3 server.
Create the objects like this:
Set objPop3 = CreateObject( "ActiveEmail.Pop3" )
The following code will collect information such as the username and the password to connect to the POP3 server. If it's a secure server the port number will be set to 995.
' Read POP3 properties strPop3 = ReadInput( "Enter POP3 Server", "pop.gmail.com", false ) strPop3Account = ReadInput( "Enter POP3 Account", "", false ) strPop3Password = ReadInput( "Enter POP3 Password", "", false )
You can now receive E-mail messages.
The following VBScript code will download all the messages from the POP3 server:
For i = 1 to numMessages
Set objPop3Mail = objPop3.GetEmailHeader( i )
Wscript.Echo "GetEmailHeader (" & i & "), result: " & objPop3.LastError
If ( objPop3.LastError = 0 ) Then
WScript.Echo "MessageID : " & objPop3Mail.ID
WScript.Echo " From : " & objPop3Mail.FromAddress
WScript.Echo " From Name : " & objPop3Mail.FromName
WScript.Echo " To : " & objPop3Mail.ToAddress
WScript.Echo " Subject : " & objPop3Mail.Subject
WScript.Echo " Date : " & objPop3Mail.Date
WScript.Echo vbCrLf
End If
Next
Following you can find the full source code which is also included in the ActiveEmail Toolkit package.
' ********************************************************************
'
' ActiveXperts ActiveEmail Toolkit
'
' List mailbox messages on a POP3 server
'
' (c) Copyright ActiveXperts Software - www.activexperts.com
'
' ********************************************************************
Option Explicit
Dim objPop3, objPop3Mail, numMessages, i
Dim strPop3, strPop3Account, strPop3Password
' Create POP3 object
Set objPop3 = CreateObject( "ActiveEmail.Pop3" )
' Display ActiveXperts ActiveEmail Toolkit Version
WScript.Echo "ActiveXperts ActiveEmail Toolkit Version " & objPop3.Version &
"; Build " & objPop3.Build &
"; Module " & objPop3.Module
' Display if the ActiveXperts ActiveEmail Toolkit is registered.
WScript.Echo "Expiration date: " & objPop3.ExpirationDate & vbCrLf
' Set Logfile
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
objPop3.LogFile = fso.GetSpecialFolder(2) & "\POP3_ListMessages.txt"
WScript.Echo "Log file can be found here:"
Wscript.Echo objPop3.LogFile
' Read POP3 properties
strPop3 = ReadInput( "Enter POP3 Server", "pop.gmail.com", false )
strPop3Account = ReadInput( "Enter POP3 Account", "", false )
strPop3Password = ReadInput( "Enter POP3 Password", "", false )
' Set secure if necessary
If( LCase( strPop3 ) = "pop.gmail.com" ) Then
objPop3.SetSecure 995
Wscript.Echo "SetSecure, result: " & objPop3.LastError
End If
If (objPop3.LastError = 0) Then
' Connect to the POP3 server
objPop3.Connect strPop3, strPop3Account, strPop3Password
Wscript.Echo "Connect, result: " & objPop3.LastError
End If
If (objPop3.LastError = 0) Then
' Count messages
numMessages = objPop3.CountMessages()
Wscript.Echo "CountMessages, result: " & objPop3.LastError
End If
If (objPop3.LastError = 0) Then
WScript.Echo "New message(s) on server: " & numMessages
' List all messages
if (numMessages > 0) Then
WScript.Echo "Listing messages..."
For i = 1 to numMessages
Set objPop3Mail = objPop3.GetEmailHeader( i )
Wscript.Echo "GetEmailHeader (" & i & "), result: " & objPop3.LastError
If ( objPop3.LastError = 0 ) Then
WScript.Echo "MessageID : " & objPop3Mail.ID
WScript.Echo " From : " & objPop3Mail.FromAddress
WScript.Echo " From Name : " & objPop3Mail.FromName
WScript.Echo " To : " & objPop3Mail.ToAddress
WScript.Echo " Subject : " & objPop3Mail.Subject
WScript.Echo " Date : " & objPop3Mail.Date
WScript.Echo vbCrLf
End If
Next
End If
End If
' Disconnect
objPop3.Disconnect
WScript.Echo "Disconnected."
WScript.Echo "Ready."
' ***************************************************************************
' Function ReadInput
' ***************************************************************************
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.
The ActiveEmail Toolkit 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.