How can we help?

AxEmail.Pop3


Introduction

Skip to properties and methods

The Pop3 object can be used to connect to a POP3 server and receive email messages.

Receive emails through POP3

Receive email messages through the POP3 protocol

Set objPop3 = CreateObject("AxEmail.Pop3")          ' Create the POP3 protocol object
Set objMail = CreateObject("AxEmail.Message")       ' Create the email message object

Wscript.Echo "Auron Email Component Version"  & objPop3.Version & "; Build"  & _
  objPop3.Build & "; Module"  & objPop3.Module
WScript.Echo "License Status:"  & objPop3.LicenseStatus & vbCrLf

objPop3.LogFile = "log.txt"                         ' Keep a session log

' Open a connection to the POP3 server
objPop3.SetSecure
objPop3.Connect "pop.gmail.com", "me@gmail.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If

' Retrieve all new messages
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  
  
  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText
  
  For j = 1 to objMail.CountAttachments()
    strName = objMail.GetAttachmentName(j)
    WScript.Echo "  Attachment found:"  & strName
    ' Uncomment the following lines to save the attachments.
    'strPath = "C:\Temp\" & strName
    'WScript.Echo "  Saving attachment to :"  & strPath
    'objMail.SaveAttachment j, strPath
  Next    
Next

objPop3.Disconnect
WScript.Echo "Disconnected"

Properties and Methods

Property Type Read/Write Description
Version String Read Version number of the Auron Email Component
Build String Read Build number of the Auron Email Component
Module String Read Module name of the Auron Email Component
LicenseStatus String Read License Status
LicenseKey String Read/Write License Key
LastError Number Read Result of the last called method
LogFile String Read/Write The path to a logfile which can be used for troubleshooting
HostPort Number Read/Write The host port for the POP3 server
Authentication Number Read/Write The authentication method
LastPop3Response String Read/Write The host port for the POP3 server
TimeoutConnect Number Read/Write Timeout (msecs) for a connection to be established
TimeoutAuthentication Number Read/Write Timeout (msecs) to authenticate
TimeoutCommand Number Read/Write Timeout (msecs) for each POP3 command to complete
TimeoutData Number Read/Write Timeout (msecs) for the POP3 RETR command to complete

Method Description
Clear Reset all properties to their default values
SaveLicenseKey Save the License Key in the registry
GetErrorDescription Get the description of the given error
Sleep Sleep for the specified number of milliseconds
SetSecure Enable TLS/SSL and set the correct port number
Connect Connect to the specified POP3 server
Disconnect Disconnect from the POP3 server
IsConnected Returns the connected state
CountMessages Count the number of messages in the mail-drop
DeleteMessage Delete a message from the mail-drop
GetEmailHeader Retrieve the email header
GetEmailMessage Retrieve the email message

Version property

Return the version number of the Auron Email Component

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Wscript.Echo "Auron Email Component Version"  & objPop3.Version & "; Build"  & _
  objPop3.Build & "; Module"  & objPop3.Module
WScript.Echo "License Status:"  & objPop3.LicenseStatus & vbCrLf
...

Build property

Return the build number of the Auron Email Component.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Wscript.Echo "Auron Email Component Version"  & objPop3.Version & "; Build"  & _
  objPop3.Build & "; Module"  & objPop3.Module
WScript.Echo "License Status:"  & objPop3.LicenseStatus & vbCrLf
...

Module property

Return the module name of the Auron Email Component.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Wscript.Echo "Auron Email Component Version"  & objPop3.Version & "; Build"  & _
  objPop3.Build & "; Module"  & objPop3.Module
WScript.Echo "License Status:"  & objPop3.LicenseStatus & vbCrLf
...

LicenseStatus property

The status of your license. In case you have not licensed the product, the property holds the trial expiration date. For details, see Product Activation.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")                 ' Create new instance
WScript.Echo "License Status:"  & objPop3.LicenseStatus
WScript.Echo "License Key:"  & objPop3.LicenseKey

LicenseKey property

A license key is required to unlock this component after the trial period has expired. Assign the LicenseKey property every time a new instance of this component is created (see code below). Alternatively, the LicenseKey property can be set automatically. This requires the license key to be stored in the registry. For details, see Product Activation.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")                 ' Create new instance
objPop3.LicenseKey = "XXXXX-XXXXX-XXXXX"                ' Assign your license key 
WScript.Echo "LicenseKey:"  & objPop3.LicenseKey

LastError property

Completion code of the last called function. To find the error description of a given error code, go to the online error codes codes page.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
objPop3.Connect "pop.example.com", "me@example.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

LogFile property

By default, LogFile holds an empty string and nothing is logged. If a valid file name is assigned to it, the Auron Email Component will write debug information to this file. Output data is written at the end of the file, the file is not cleared.

By default the log file uses the UTF16LE character encoding. To use UTF8 please prefix the log file name with the text: ‘UTF8:’ (e.g.: ‘UTF8:logfile.txt’).

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
objPop3.LogFile = "C:\Temp\Pop3.log"
objPop3.Connect "pop.example.com", "me@example.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

HostPort property

Set the host port to connect to. By default this is 110.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")

objPop3.HostPort = 8110
objPop3.Connect "pop.example.com", "me@example.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

Authentication property

Set the authentication method to use on the POP3 server. By default it will autodetect the preferred method.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")

objPop3.Authentication = POP3_AUTH_PLAIN
objPop3.Connect "pop.example.com", "me@example.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

LastPop3Response property

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")

objPop3.Connect "pop.example.com", "me@example.com", "password"
WScript.Echo "Server reponse:"  & objPop3.LastPop3Response
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

TimeoutConnect property

Timeout (in milliseconds) for a connection to be established.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
objPop3.TimeoutConnect = 10000
objPop3.Connect "pop.example.com", "me@example.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

TimeoutAuthentication property

Timeout (in milliseconds) to authenticate to the POP3 mail server.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
objPop3.TimeoutAuthentication = 10000
objPop3.Connect "pop.example.com", "me@example.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

TimeoutCommand property

Timeout (in milliseconds) for each POP3 command to complete. This applies to all POP3 commands (e.g.: APOP, CAPA, QUIT) except the RETR command.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
objPop3.TimeoutCommand = 10000      
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  

  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText
Next
...

TimeoutData property

Timeout (msecs) for the POP3 RETR command to complete.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
objPop3.TimeoutData = 120000      
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  

  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText
Next
...

Clear method

This function resets all properties to their default values.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")   
....
objPop3.Clear
...

SaveLicenseKey method

Description:

Use SaveLicenseKey to store the license key permanently in the registry. When a license key is saved, it is restored automatically every time a new instance of the object is created. It is not recommended to save the license key if you distribute the component with your own software, because the key can be easily used by others.

Parameters:

  • None.

Return value:

Always 0. Check LastError property to see if the method was completed successfully.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")                 ' Create new instance
objPop3.LicenseKey = "XXXXX-XXXXX-XXXXX"
objPop3.SaveLicenseKey                                     ' Save license key to registry

For more information, see Product Activation.

GetErrorDescription method

GetErrorDescription provides the error description of a given error code.

Parameters:

  • The error code

Return value:

The error string.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
...
WScript.Echo "result:"  & objPop3.LastError & ","  & _
  objPop3.GetErrorDescription(objPop3.LastError)

Sleep method

This function suspends the current thread for the specified number of milliseconds.

Parameters:

  • Milliseconds to sleep

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
...
objPop3.Sleep 1000
...

SetSecure method

This function enables TLS/SSL and sets the correct port number.

Parameters:

  • Port number. Default: 995

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...
objPop3.SetSecure
objPop3.Connect "pop.gmail.com", "me@gmail.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

Connect method

This function connects to the POP3 server.

Parameters:

  • Hostname
  • Account
  • Password

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...  
objPop3.Connect "pop.gmail.com", "me@gmail.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...

Disconnect method

This function disconnects from the POP3 server.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...  
objPop3.Connect "pop.gmail.com", "me@gmail.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...
objPop3.Disconnect

IsConnected method

This function returns the connected state. True is connected, False if not connected.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...  
objPop3.Connect "pop.gmail.com", "me@gmail.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If
...
WScript.Echo objPop3.IsConnected
...
objPop3.Disconnect

CountMessages method

This function requests the number of messages in the mail drop.

Parameters:

  • None

Return value:

The number of messages in the mail-drop

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  
  
  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText    
Next
...

DeleteMessage method

This function deletes a message from the mail-drop. This prevents the mail server from including this email on the next connect.

Parameters:

  • Message Id

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  
  
  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText
  
  objPop3.DeleteMessage objMessage.ID
Next
...

GetEmailHeader method

This function only returns the email header. On most mail servers this will be faster than retrieving the entire message body.

Parameters:

  • Message Id

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailHeader(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  
  
  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject    
Next
...

GetEmailMessage method

This function retrieves the email message

Parameters:

  • Message Id

Return value:

Always 0.

Example:

Set objPop3 = CreateObject("AxEmail.Pop3")
Set objMail = CreateObject("AxEmail.Message")
...
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  
  
  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText
Next
...

The Pop3 object can be used to connect to a POP3 server and receive email messages.

Receive emails through POP3

Receive email messages through the POP3 protocol

Set objPop3 = CreateObject("AxEmail.Pop3")          ' Create the POP3 protocol object
Set objMail = CreateObject("AxEmail.Message")       ' Create the email message object

Wscript.Echo "Auron Email Component Version"  & objPop3.Version & "; Build"  & _
  objPop3.Build & "; Module"  & objPop3.Module
WScript.Echo "License Status:"  & objPop3.LicenseStatus & vbCrLf

objPop3.LogFile = "log.txt"                         ' Keep a session log

' Open a connection to the POP3 server
objPop3.SetSecure
objPop3.Connect "pop.gmail.com", "me@gmail.com", "password"
If objPop3.LastError <> 0 Then
  WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
  WScript.Quit
End If

' Retrieve all new messages
For i = 1 to objPop3.CountMessages()
  Set objMail = objPop3.GetEmailMessage(i)
  If objPop3.LastError <> 0 Then
    WScript.Echo "Error:"  & objPop3.GetErrorDescription(objPop3.LastError)  
    objPop3.Disconnect
    WScript.Quit
  End If  
  
  WScript.Echo "--------------------------------------------------------------"
  WScript.Echo objMail.Date
  WScript.Echo objMail.FromAddress
  WScript.Echo objMail.Subject
  WScript.Echo objMail.BodyPlainText
  
  For j = 1 to objMail.CountAttachments()
    strName = objMail.GetAttachmentName(j)
    WScript.Echo "  Attachment found:"  & strName
    ' Uncomment the following lines to save the attachments.
    'strPath = "C:\Temp\" & strName
    'WScript.Echo "  Saving attachment to :"  & strPath
    'objMail.SaveAttachment j, strPath
  Next    
Next

objPop3.Disconnect
WScript.Echo "Disconnected"