GetSizeOfMails Method

Get the total size of mails existing on POP3 & IMAP4 server.

[Syntax]
C++: HRESULT GetSizeOfMails( long* pVal )
Visual Basic: GetSizeOfMails() As long
C#: long GetSizeOfMails()

Return Value

This method returns total size of mails existing on POP3 & IMAP4 server. If it fails, the return value is -1.

Usage Example

[Visual Baisc]
Sub GetTotalSize( pop3Server As String, pop3User As String, pop3Password As String )
  Dim oPop3 As ANPOPLib.POPMAIN
  Dim oMsg As ANPOPLib.POPMSG
  Dim nRet, nTotalSize As Integer
  Dim err As String
  
  Set oPop3 = new ANPOPLib.POPMAIN 'Create object instance
  Set oMsg  = new ANPOPLib.POPMSG
   
  'For IMAP4 server, please add the following code
  'oPop3.IMAP4Connection = 1
  'oPop3.ServerPort = 143
    
  err = ""
  nRet = oPop3.Connect( pop3Server, pop3User, pop3Password ) 'Connect pop3 server
  If nRet <> 0 Then
    err = "error with connecting server"
    goto ErrorHandler
  End If
  
  nTotalSize = oPop3.GetSizeOfMails() 'Get total size of emails
  If nTotalSize = -1 Then
    err = "error with GetSizeOfMails"
    goto ErrorHandler  
  End If
  
ErrorHandler:
  Call oPop3.Close() 'Close connection
  Set oPop3 = Nothing
  Set oMsg = Nothing
  
End Sub
[C#]
public void GetTotalSize( string pop3Server, string pop3User, string pop3Password )
{
  POPMAINClass oPop3 = new POPMAINClass();  //Create object instance
  POPMSGClass oMsg = new POPMSGClass();
  int nRet = 0, nTotalSize = 0;
    
  try
  {
     
    //For IMAP4 server, please add the following code
    //oPop3.IMAP4Connection = 1;
    //oPop3.ServerPort = 143; 
      
    nRet = oPop3.Connect( pop3Server, 
                          pop3User, 
                          pop3Password ); //Connect pop3 server
    if( nRet != 0 )
      throw new Exception( "error with Connect" );
  
    nTotalSize = oPop3.GetSizeOfMails(); //Get total size of emails
    if( nTotalSize == -1 )
      throw new Exception( "error with GetSizeOfMails" );
  }
  catch( Exception e )
  {
    Console.WriteLine( e.Message );
  }
  
  oPop3.Close(); //Close connection
  oPop3 = null;
  oMsg = null;
}
[Visual C++]
#include <comdef.h>
#include <string>
#include <iostream>
using namespace std;
#import "c:\program files\adminsystem.net\anpop\anpop.dll" no_namespace

VOID GetTotalSize( const char* lpszServer, 
                   const char* lpszUser, 
                   const char* lpszPassword )
{
  ::CoInitialize( NULL );
  
  IPOPMAINPtr	oPop3("ANPOP.POPMAIN");
  IPOPMSGPtr	oMsg("ANPOP.POPMSG");
  int nRet = 0, nTotalSize = 0;
  
  try
  {
 
    //For IMAP4 server, please add the following code
    //oPop3->IMAP4Connection = 1;
    //oPop3->ServerPort = 143;
      
    nRet = oPop3->Connect( _bstr_t(lpszServer), 
                              _bstr_t(lpszUser), 
                              _bstr_t(lpszPassword));
    if( nRet != 0 )
      throw string( "error with Connect" );
      
    nTotalSize = oPop3->GetSizeOfMails(); //Get total size of emails
    if( nTotalSize == -1 )
      throw string( "error with GetSizeOfMails" );
  }
  catch( string &e )
  {
    cout << e << endl;
  }		

  oPop3->Close();   //Close connection
  oPop3.Release();
  oMsg.Release();
  ::CoUninitialize();
}

See Also

GetMsgID Method
GetTotalOfMails Method
Retrieve Method

Asynchronous mode

OnGetSizeOfMails Event
OnError Event


2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.