tfPop3UserConnect

Jump to: navigation, search

Table of Contents >> Optional Protocols >> POP3


#include <trsocket.h>


int tfPop3UserConnect (
ttPop3ClientHandle pop3Handle,
struct sockaddr_storage * serverSockAddrPtr,
char * usernamePtr,
char * passwordPtr
);


Function Description

This function is called when the user wants to make a connection to the POP3 server. The same POP3 handle can be connected and disconnected multiple times. The 'pop3Handle' remains allocated unless tfPop3FreeSession() is called. Please make sure that the server port number is the POP3 port (generally it is 110, and in network byte order).


Parameters

  • pop3Handle
    The POP3 session handle.
  • serverSockAddrPtr
    A pointer to the sockaddr_storage structure holding the address of the server.
  • usernamePtr
    The username string.
  • passwordPtr
    The password string.


Returns

  • TM_ENOERROR
    Success
  • TM_SOCKET_ERROR
    Failure


Note Note: TM_SOCKET_ERROR means that this socket call has failed and the errorCode has been set on the socket itself.

To retrieve the socket error the user must call tfGetSocketError(socketDescriptor).


Possible socket errors

  • TM_EINVAL
    One of the parameters is invalid.
  • TM_EALREADY
    The POP3 session pointed to by 'pop3Handle' is already connected.
  • TM_ENOBUFS
    Insufficient memory to complete the operation.
  • TM_EINPROGRESS
    The POP3 session is operating in non-blocking mode and a previous call to tfPop3UserConnect() is currently executing. The user should continue calling tfPop3UserConnect() until it returns an error code other than TM_EINPROGRESS.


Example Code

 
pop3Handle = tfPop3NewSession(...)
/* make sure that server port is 110 */
serverSockAddr.ss_port = htons(110);
errorCode = tfPop3UserConnect(pop3Handle,
                              &serverSockAddr,
                              "test@domain.com",
                              "testpassword");
while(errorCode == TM_EINPROGRESS)
{
    errorCode = tfPop3UserExecute(pop3Handle);
}
assert(errorCode == TM_ENOERROR);
 
/* when you reach here, the connection is successfully established */
 


Table of Contents >> Optional Protocols >> POP3