SSL_init Method

Initializes security library for POP3 & IMAP4 SSL/TLS connection.

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

Return Value

This method returns zero if succeeded, otherwise return valus is non-zero.

Remarks

ANPOP uses SSL/TLS connection to retrieve email after this method is invoked. To cancel SSL/TLS mode, you can invoke SSL_uninit method.

This method requires IE5.0 or later in Windows95 or SP4 or later in Windows NT4.0.

To use SSL/TLS in ANPOP, an extra SSL/TLS plus license is required. For details, please refer to SSL_registerkey property.

Usage Example

[Visual Baisc]
Sub Retrieve( pop3Server As String, pop3User As String, pop3Password As String )
  Dim oPop3 As ANPOPLib.POPMAIN
  Dim oMsg As ANPOPLib.POPMSG
  Dim i, nRet, nSize, nCount As Integer
  Dim emailContent, messageId, errStr As String
  
  Set oPop3 = new ANPOPLib.POPMAIN 'Create object instance
  Set oMsg  = new ANPOPLib.POPMSG
  
  If oPop3.SSL_init() <> 0 Then
    errStr = "Initialize ansslplus failed"
    goto ErrorHandler
  End If
  
  oPop3.SeverPort = 995 'POP3 servers usually use this port as alone SSL/TLS port.
   
  'For IMAP4 server, please add the following code
  'oPop3.IMAP4Connection = 1
  'oPop3.ServerPort = 993
    
  errStr = ""
  nRet = oPop3.Connect( pop3Server, pop3User, pop3Password ) 'Connect pop3 server
  If nRet <> 0 Then
    errStr = "error with connecting server"
    goto ErrorHandler
  End If
  
  nCount = oPop3.GetTotalOfMails() 'Get total count of emails
  If nCount = -1 Then
    errStr = "error with GetTotalOfMails"
    goto ErrorHandler  
  ElseIf nCount = 0 Then
    errStr = "no email"
    goto ErrorHandler
  End If
  
  For i = 1 To nCount
    nSize = oPop3.GetMsgSize(i) 'Get email size
    If nSize = -1 Then
      errStr = "error with GetMsgSize"   
	  goto ErrorHandler
    End If
    
    messageId = oPop3.GetMsgID(i) 'Get message-id
    If messageId = vbnullstring Then
	  errStr = "error with GetMsgId"  
	  goto ErrorHandler
    End If
    
    emailContent = oPop3.Retrieve(i) 'Retrieve email
    If emailContent = vbnullstring Then
      errStr = "error with Retrieve" 
      goto ErrorHandler
    End If
    
    oMsg.RawContent = emailContent
    nRet = oMsg.ExportFile( "c:\pop3Test_" & i & ".eml") 'Save email
    If nRet <> 0 Then
      errStr = "error with ExportFile"
      goto ErrorHandler
    End If
    
    If oPop3.Delete(i) <> 0 Then 'Delete email from server
      errStr = "error with Delete"
      goto ErrorHandler
    End If
  Next
  
ErrorHandler:
  Call oPop3.Close() 'Close connection
  oPop3.SSL_uninit
  Set oPop3 = Nothing
  Set oMsg = Nothing
  
End Sub
[C#]
public void Retrieve( string pop3Server, string pop3User, string pop3Password )
{
  POPMAINClass oPop3 = new POPMAINClass();  //Create object instance
  POPMSGClass oMsg = new POPMSGClass();
  int i = 0, nRet = 0, nSize = 0, nCount = 0;
  string emailContent = "", messageId = "";
  
  try
  {
    nRet = oPop3.SSL_init();
    if( nRet != 0 )
      throw new Exception("initialize ansslplus failed" );
      
    //POP3 servers usually use this port as alone SSL/TLS port.
    oPop3.ServerPort = 995; 
      
    //For IMAP4 server, please add the following code
    //oPop3.IMAP4Connection = 1;
    //oPop3.ServerPort = 993;  
       
    nRet = oPop3.Connect( pop3Server, 
                         pop3User, 
                         pop3Password ); //Connect pop3 server
    if( nRet != 0 )
      throw new Exception( "error with Connect" );
  
    nCount = oPop3.GetTotalOfMails(); //Get total count of emails
    if( nCount == -1 )
      throw new Exception( "error with GetTotalOfMails" );
    else if( nCount == 0 )
      throw new Exception( "no email" );
  
    for( i = 1; i <= nCount; i++ )
    {
      nSize = oPop3.GetMsgSize(i); //Get email size
      if( nSize == -1 )
        throw new Exception( "error with GetMsgSize" );
    
      messageId = oPop3.GetMsgID(i); //Get message-id
      if( messageId == null )
        throw new Exception( "error with GetMsgID" );
    
      emailContent = oPop3.Retrieve(i); //Retrieve email
      if( emailContent == null )
        throw new Exception( "error with Retrieve" );
    
      oMsg.RawContent = emailContent;
      nRet = oMsg.ExportFile( 
               String.Format( "c:\\pop3Test_{0}.eml", i )); //Save email
      if( nRet != 0 )
        throw new Exception( "error with ExportFile" );
    
      if( oPop3.Delete(i)!= 0 ) //Delete email from server
        throw new Exception( "error with Delete" );
    }
  }
  catch( Exception e )
  {
    Console.WriteLine( e.Message );
  }
  
  oPop3.Close(); //Close connection
  oPop3.SSL_uninit();
  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 Retrieve( const char* lpszServer, 
              const char* lpszUser, 
              const char* lpszPassword )
{
  ::CoInitialize( NULL );
  
  IPOPMAINPtr	oPop3("ANPOP.POPMAIN");
  IPOPMSGPtr	oMsg("ANPOP.POPMSG");
  int i = 0, nCount = 0, nRet = 0, nSize = 0;
  _bstr_t emailContent = "", messageId = "";
  
  try
  {
    if( oPop3->SSL_init() != 0 )
      throw string( "initialize ansslplus failed" );
	
    //POP3 servers usually use this port as alone SSL/TLS port.	
    oPop3->ServerPort = 995;  
 
    //For IMAP4 server, please add the following code
    //oPop3->IMAP4Connection = 1;
    //oPop3->ServerPort = 993;   
    nRet = oPop3->Connect( _bstr_t(lpszServer), 
                       _bstr_t(lpszUser), 
                       _bstr_t(lpszPassword));
    if( nRet != 0 )
      throw string( "error with Connect" );
      
    nCount = oPop3->GetTotalOfMails(); //Get total count of emails
    if( nCount == -1 )
      throw string( "error with GetTotalOfMails" );
    else if( nCount == 0 )
      throw string( "no email" );
  
    for( i = 1; i <= nCount; i++ )
    {
      nSize = oPop3->GetMsgSize(i); //Get email size
      if( nSize == -1 )
        throw string( "error with GetMsgSize" );
    
      messageId = oPop3->GetMsgID(i); //Get message-id
      if( messageId == _bstr_t((BSTR)NULL))
        throw string( "error with GetMsgID" );
    
      emailContent = oPop3->Retrieve(i); //Retrieve email
      if( emailContent == _bstr_t((BSTR)NULL))
        throw string( "error with Retrieve" );
    
      oMsg->RawContent = emailContent;
      char szFile[MAX_PATH];
      memset( szFile, 0, sizeof(szFile));
      ::sprintf( szFile, "c:\\pop3Test_%d.eml", i );
      nRet = oMsg->ExportFile( _bstr_t(szFile)); //Save email
      if( nRet != 0 )
        throw string( "error with ExportFile" );
    
      if( oPop3->Delete(i)!= 0 ) //Delete email from server
        throw string( "error with Delete" );
    }
  }
  catch( string &e )
  {
    cout << e << endl;
  }		

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

See Also

SSL_uninit Method
SSL_registerkey Property


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