ANPOP Developers Center > Using ANPOP in WSH/VBScript/JScript

You should download the anpop installer and install it on your machine at first. If you want to distribute or deploy anpop without anpop installer, please click here to learn more.

Create object instance

Use CreateObject in vbs and new ActiveXObject in JScript to create object instances.

[vbs]
Dim oPop3, oMsg, oStore
Set oPop3 = CreateObject("ANPOP.POPMAIN")
Set oMsg = CreateObject("ANPOP.POPMSG")
Set oStore = CreateObject("ANPOP.MSGSTORE")
[jscript]
var oPop3 = new ActiveXObject("ANPOP.POPMAIN");
var oMsg = new ActiveXObject("ANPOP.POPMSG");
var oStore = new ActiveXObject("ANPOP.MSGSTORE");

Simple project to retrieve email summary

The following sample demonstrates how to retrieve email summary on pop3 server.

[vbs]
Dim args, info
Set args = WScript.Arguments
If args.Count < 3 Then
  info =  "Usage: PreviewEmail.vbs [pop3server] [user] [password]" & Chr(13) & Chr(10)
  info = info & "   eg: PreviewEmail.vbs mail.adminsystem.net test@adminsystem.net test"
  WScript.Echo info
  WScript.Quit
End If

Dim oPop3, oMsg, nRet, i, nCount, nSize, headerContent, nullString
nullString = ""

WScript.Echo "Connecting " & args(0) & " ..."

Set oPop3 = CreateObject("ANPOP.POPMAIN")
Set oMsg = CreateObject("ANPOP.POPMSG")

nRet = oPop3.Connect(args(0), args(1), args(2))
If nRet <> 0 Then
  WScript.Echo "Error with connect server, please make sure server, user, password are correct"
  WScript.Quit
End If

nCount = oPop3.GetTotalOfMails()
If nCount = -1 Then
  WScript.Echo "Error with GetTotalOfMails method"
  WScript.Quit
End If

WScript.Echo "Total " & nCount & " email(s)" & Chr(13) & Chr(10)

For i = 1 To nCount
  nSize = oPop3.GetMsgSize(i)
  If nSize = -1 Then
    WScript.Echo "Error with GetMsgSize method"
    Exit For
  End If

  headerContent = oPop3.GetMsgHeader(i)
  If headerContent = nullString Then
    WScript.Echo "Error with GetMsgHeader method"
    Exit For
  End If
	
  oMsg.RawContent = headerContent
  info = i & ": size: " & nSize & " bytes, date: " & oMsg.GetDate() & Chr(13) & Chr(10)
  info = info & "From: " & oMsg.GetFrom() & "<" & oMsg.GetFromAddress() & ">" & Chr(13) & Chr(10)
  info = info & "Subject: " & oMsg.GetSubject() & Chr(13) & Chr(10)
  WScript.Echo info
Next

oPop3.Close
WScript.Quit

More samples

Please refer to SCRIPTING sample in ANPOP installation package.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2008 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map