Jump to content



Recommended Posts

G'day All

I searched throught the forum for something like this but didn't have much luck untill 'monoceres' asked a question in another thread and I did a slightly different search and came up with THIS from 'RobSaunders'. After a little cleaning up this little script may come in handy for someone else.

Simply give the script the username, password, server and optionally port and it will return TRUE if everything is OK or False if it isn't. @error codes are returned to indicate what was wrong in the information. The header has all the information you may need and an example is included.

If any one has any suggestions or finds a problem please let me know ASAP.

    If _PopCheck('Something@somewhere.com', 'password', "mail.somewhere.com") Then
    MsgBox(0, "WORKING", "ALL is OK!" & @CR & "Password good")
    MsgBox(0, "ERROR", "Error number = " & @error & @CR & " Extended = " & @extended)

; #FUNCTION# ;====================================================================================================================
; Name...........: _PopCheck
; Description ...: Check username, password and server are correct for a popserver
; Syntax.........: _PopCheck($sUserID, $sPassword, $sServer, $nPort)
; Parameters ....:  $sUserID    - User id (usually the full Email address)
;                   $sPassword  - Password for pop account
;                   $sServer    - POP server address
;                   $nPort      - POP port on server (Default = 110)
; Return values .: Success - returns TRUE
;                  Failure - Returns FALSE and Sets @Error:
;                  |1 - Unable to start TCP                     @extended = Windows API WSAStartup return
;                  |2 - Unable to convert server to IP address  @extended = Windows API WSAGetError return
;                  |3 - Bad conneciton                          @extended = Windows API WSAGetLasterror return
;                  |4 - Communications failure (Disconnected)   @extended = Windows API WSAGetLasterror return
;                  |5 - invalid user name or password
; Author ........: Storme (john Morrison)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......;
Func _PopCheck($sUserID, $sPassword, $sServer, $nPort = 110)

    Local $nRtnVal = TCPStartup()
    If Not $nRtnVal Then
        SetError(1, @error) ; Unable to start TCP
        Return False

    Local $sIp = TCPNameToIP($sServer)
    If $sIp = "" Then
        SetError(2, @error) ; Unable to convert server to IP address
        Return False

    Local $socket = TCPConnect($sIp, $nPort)
    If $socket = -1 Then
        ;* ConsoleWrite('Error: Bad connection' & @CRLF)
        SetError(3, @error) ; Bad conneciton
        Return False
        Local $sStep = 'login'
            Local $sRecv = TCPRecv($socket, 512)
            If @error Then
                ;* ConsoleWrite('Notice: Disconnected!' & @CRLF)
                SetError(4, @error) ; Communications failure
                Return False
            ElseIf StringInStr($sRecv, '+OK') = 1 Then
                ;* ConsoleWrite($sRecv & @CRLF)
                Switch $sStep
                    Case 'login'
                        ;* ConsoleWrite('Login: Username...' & @CRLF)
                        TCPSend($socket, 'user ' & $sUserID & @CRLF)
                        $sStep = 'pass'
                    Case 'pass'
                        ;* ConsoleWrite('Login: Password...' & @CRLF)
                        TCPSend($socket, 'pass ' & $sPassword & @CRLF)
                        $sStep = 'finished'
                    Case 'finished'
                        ;* ConsoleWrite('Disconnecting')
                        TCPSend($socket, 'QUIT' & @CRLF)
                        $socket = -1
                        $sStep = ''
            ElseIf StringInStr($sRecv, '-ERR') = 1 Then
                ;* ConsoleWrite('Error: ' & $sRecv & @CRLF)
                ;* ConsoleWrite('Disconnecting')
                TCPSend($socket, 'QUIT' & @CRLF)
                SetError(5) ; invalid user name or password
                Return False
        Until $socket = -1
    Return True
EndFunc   ;==>_PopCheck

Another AutoIT Lover :D

John Morrison

EDIT:6th June 2009: Fixed minor code mistake

Edited by storme
Link to comment
Share on other sites

What about SSL?

Sorry but I don't know anything about SSL and don't have any accounts I can experiment on so there is nothing I can do at the moment. So if you use SSL and more importantly if you can supply some details on how to handle SSL then I'd be interested to add it to the code.

Come to think of it I don't think any of my customers use SSL on their pop accounts.

Thanks for the reply

John Morrison

Link to comment
Share on other sites

Why do you do:


TCPSend($socket, 'QUIT' & @CRLF)



That woule be because I messed up :D

The original script didn't user "QUIT" and I didn't like leaving it up to the server to clean up.

So I added the "QUIT/TCPCloseSocket" and missed removeing the original TCPCloseSocket.

I'll edit the first message with the new code.

Thanks for picking that up

John Morrison

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...