Announcement

Collapse
No announcement yet.

I need a way of checking my mail....

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • I need a way of checking my mail....

    ....just to see if anything is there.

    That's it. Nothing else. Just to see if there's anything in my inbox. Don't need to download them. Don't need a spam filter, no anything. Just check the inbox for occupancy.

    I looked the forums buy maybe I'm using the wrong search terms.
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    By Don Dickinson. No source code on this one (not a PB program.)
    http://www.greatwebdivide.com/software_popwiz.htm


    Mail program using Outlook Express: C:\Program Files\Outlook Express\msimn.exe
    Mail program using Incredimail: C:\Program Files\IncrediMail\bin\IncMail.exe
    Do NOT enclose path within quotes.
    Last edited by Mike Doty; 22 Apr 2009, 08:01 PM.
    https://duckduckgo.com instead of google

    Comment


    • #3
      I forget who was the originator of the following code but it is a simple matter as you do a normal connection to your POP3 server and then log off after just retrieving the number of emails for you. You can go further and get headers ie from and subject if you wish. The following code is the three main functions you should need.
      Code:
      '------------------------------------------------------------------------------
      ' Connect to POP3 mail server.
      '
      FUNCTION Pop3Connect (Pop3Host AS STRING, USER AS STRING, _
                            password AS STRING) AS LONG
      
          LOCAL nTCP   AS LONG
          LOCAL Buffer AS STRING
      
          ON ERROR GOTO Pop3Error
          LstErr = "Error opening POP3 server"
          nTCP = FREEFILE
      
          TCP OPEN "pop3" AT Pop3Host AS nTCP
          TCP LINE nTCP, Buffer
          IF LEFT$(Buffer, 3) <> "+OK" THEN
              LstErr = "No OK on POP3 open"
              ERROR 151
          END IF
      
          TCP PRINT nTCP, "USER " + USER
          TCP LINE nTCP, Buffer
          IF LEFT$(Buffer, 3) <> "+OK" THEN
              LstErr = "Bad mail user name"
              ERROR 152
          END IF
      
          TCP PRINT nTCP, "PASS " + password
          TCP LINE nTCP, Buffer
          IF LEFT$(Buffer, 3) <> "+OK" THEN
              LstErr = "Bad mail password"
              ERROR 153
          END IF
          LstErr = ""
          FUNCTION = nTCP
          Pop3ConnErr:
          EXIT FUNCTION
      
      Pop3Error:
          CLOSE nTCP
          FUNCTION = -(ERRCLEAR)
          RESUME Pop3ConnErr
      
      END FUNCTION
      
      
      
      '------------------------------------------------------------------------------
      ' Disconnect from POP3 mail server
      '
      FUNCTION Pop3Quit (BYVAL nTCP AS LONG) AS LONG
      
          LOCAL Buffer AS STRING
      
          TCP PRINT nTCP, "QUIT"
          TCP LINE nTCP, Buffer
      
          IF LEFT$(Buffer, 3) <> "+OK" THEN
              FUNCTION = -1  'error
          END IF
          CLOSE nTCP
      END FUNCTION
      
      
      
      '------------------------------------------------------------------------------
      ' Get the status of the POP3 account
      '
      FUNCTION Pop3GetStat (BYVAL nTCP AS LONG, Messages AS LONG, MsgSize AS LONG) AS LONG
      
          LOCAL Buffer AS STRING
      
          TCP PRINT nTCP, "STAT"
          TCP LINE nTCP, Buffer
      
          IF LEFT$(Buffer, 3) <> "+OK" THEN
              FUNCTION = -154  'error
              LstErr = "Error getting POP3 STAT"
              EXIT FUNCTION
          END IF
      
          Messages = VAL(PARSE$(Buffer, " ", 2))
          MsgSize  = VAL(PARSE$(Buffer, " ", 3))
          FUNCTION = 0
      
      END FUNCTION

      Comment


      • #4
        Tested and it works great

        John,
        I wrote a test program to display results and it works great!
        All that is needed is to supply the 3 parameters.

        Displaying the headers or launching your email reader might be next.
        Adding a timer to check every so often.

        Thanks for supplying this!
        Last edited by Mike Doty; 23 Apr 2009, 03:18 PM.
        https://duckduckgo.com instead of google

        Comment


        • #5
          My pleasure but as I said the basic code is not mine, found it here somewhere though the error handling is mine and I see you picked up on the fact that the error numbers should be passed back as negatives. I just cut sections from a dll (called on a timed basis) I use which receives customer orders by email and processes them directly into their accounting package, it has another function similar to windows of GetLastError. I think I still have a copy of the original posters code which includes retrieving the entire email and then deleting it from the server. Will post it if it is of use to you.

          Comment


          • #6
            It would be of use.
            I've added a helper function for calling multiple accounts and entering
            the server name, user name and password. I will also post if anyone is interested.
            https://duckduckgo.com instead of google

            Comment


            • #7
              Just supply: popserver$, username$, password$, soundFile$

              Code:
                #INCLUDE "win32api.inc"
               
                $WaveFile = "gotmail.wav"
                GLOBAL gsResults AS STRING 'optional, combine all results into a string
               
              FUNCTION PBMAIN AS LONG
               
                LOCAL sPop3Host,sUser,sPassword  AS STRING
                LOCAL MsgCount,MsgSize,Result    AS LONG
               
                sPop3Host = "pop.net"
                sUser     = "username"
                sPassword = "password"
                Result = Pop(sPop3Host,sUser,sPassword,MsgCount, MsgSize&)
                IF MsgCount THEN PlayIt
               
                sPop3Host = "pop.net"
                sUser     = "username"
                sPassword = "password"
                Result = Pop(sPop3Host,sUser,sPassword,MsgCount, MsgSize&)
                IF MsgCount THEN PlayIt
               
                ? gsResults
               
              END FUNCTION
               
              SUB PlayIt
                CALL PlaySound($WaveFile, %NULL ,%SND_SYNC) 'use sync so sound file completes
              END SUB
               
              FUNCTION Pop( sPop3Host        AS STRING , _
                            sUser            AS STRING , _
                            sPassword        AS STRING , _
                            NumberOfMessages AS LONG   , _
                            MsgSize          AS LONG ) AS LONG
                LOCAL hTCP, Result AS LONG
                LOCAL sResults AS STRING  'optionally display results
                hTCP = Pop3Connect ( sPop3Host, sUser, sPassword)
                IF hTCP > -1 THEN
                  REM Pop account reached
                  Result = Pop3GetStat (hTCP&, NumberOfMessages&, MsgSize&)
                  IF Result = 0 THEN
                    LogIt  "Messages:" + STR$(NumberOfMessages&)
                    LogIt  "Length:"   + STR$(MsgSize&)
                  ELSE
                    LogIt "Error getting POP3 STAT"
                  END IF
               
                  Result = Pop3Quit (hTCP)
                  IF result = -1 THEN
                    LogIt "Error occurred closing server"
                  ELSE
                    LogIt "Bye, no problems"
                  END IF
                'error connecting to POP3
                ELSE
                  FUNCTION = hTCP
                  SELECT CASE hTCP
                    CASE -152:LogIt "No OK on POP3 open"
                    CASE -152:LogIt "Bad user name"
                    CASE -153:LogIt "Bad password"
                    CASE ELSE:LogIt "Error connecting to POP3 "+ STR$(hTCP)
                  END SELECT
                END IF
              END FUNCTION
              SUB LogIt(s AS STRING)
                s = s + $CRLF
                gsResults = gsResults + s
              END SUB
               
                '------------------------------------------------------------------------------
              ' Connect to POP3 mail server.
              '
              FUNCTION Pop3Connect (Pop3Host AS STRING, USER AS STRING, _
                                    password AS STRING) AS LONG
                  LOCAL nTCP   AS LONG
                  LOCAL Buffer AS STRING
                  'added this
                  LOCAL LstErr AS STRING
               
                  ON ERROR GOTO Pop3Error
                  LstErr = "Error opening POP3 server"
                  nTCP = FREEFILE
                  TCP OPEN "pop3" AT Pop3Host AS nTCP
                  TCP LINE nTCP, Buffer
                  IF LEFT$(Buffer, 3) <> "+OK" THEN
                      LstErr = "No OK on POP3 open"
                      ERROR 151
                  END IF
                  TCP PRINT nTCP, "USER " + USER
                  TCP LINE nTCP, Buffer
                  IF LEFT$(Buffer, 3) <> "+OK" THEN
                      LstErr = "Bad mail user name"
                      ERROR 152
                  END IF
                  TCP PRINT nTCP, "PASS " + password
                  TCP LINE nTCP, Buffer
                  IF LEFT$(Buffer, 3) <> "+OK" THEN
                      LstErr = "Bad mail password"
                      ERROR 153
                  END IF
                  LstErr = ""
                  FUNCTION = nTCP
                  Pop3ConnErr:
                  EXIT FUNCTION
              Pop3Error:
                  CLOSE nTCP
                  FUNCTION = -(ERRCLEAR)
                  RESUME Pop3ConnErr
              END FUNCTION
              '------------------------------------------------------------------------------
              ' Disconnect from POP3 mail server
              '
              FUNCTION Pop3Quit (BYVAL nTCP AS LONG) AS LONG
                  LOCAL Buffer AS STRING
                  TCP PRINT nTCP, "QUIT"
                  TCP LINE nTCP, Buffer
                  IF LEFT$(Buffer, 3) <> "+OK" THEN
                      FUNCTION = -1  'error
                      REM ? "Error"
                  END IF
                  CLOSE nTCP
              END FUNCTION
              '------------------------------------------------------------------------------
              ' Get the status of the POP3 account
              '
              FUNCTION Pop3GetStat (BYVAL nTCP AS LONG, Messages AS LONG, MsgSize AS LONG) AS LONG
               
                  LOCAL Buffer AS STRING
                  'add this
                  LOCAL LstErr AS STRING
                  TCP PRINT nTCP, "STAT"
                  TCP LINE nTCP, Buffer
                  IF LEFT$(Buffer, 3) <> "+OK" THEN
                      FUNCTION = -154  'error
                      LstErr = "Error getting POP3 STAT"
                      EXIT FUNCTION
                  END IF
                  Messages = VAL(PARSE$(Buffer, " ", 2))
                  MsgSize  = VAL(PARSE$(Buffer, " ", 3))
                  FUNCTION = 0
              END FUNCTION
              Last edited by Mike Doty; 23 Apr 2009, 03:21 PM. Reason: Added sound
              https://duckduckgo.com instead of google

              Comment


              • #8
                Mike attached is the full original code.
                Attached Files

                Comment


                • #9
                  I'll try to find a way to extract a RAR file. Never had to before.
                  Thanks, the pop3 checker I have now is multi-threaded and interesting.
                  It launches my email program and checks multiple pop3 servers and gives
                  me different sound notifications based upon which account is receiving the mail. I need to put a GUI around it using PB Forms.
                  I'm having a problem with it keep telling me the email is there until it is read.

                  Arthur: thank you for converting it!
                  Last edited by Mike Doty; 24 Apr 2009, 09:22 AM.
                  https://duckduckgo.com instead of google

                  Comment


                  • #10
                    In zip format
                    Attached Files
                    "The trouble with quotes on the Internet is that you can never know if they are genuine." - Abraham Lincoln.

                    Comment


                    • #11
                      Mike
                      Apologies, I stopped using Zips because so many people use M$'s email programs and they will block attachments even containing code with a .bas extension, but they don't look inside Rars. Winrar is good.
                      Your other problem is tricky I guess you need to store the last count in a static or on disk if the program closes, notify when it goes up or reset to zero if it goes down.
                      A slower but more accurate method would be to download the emails but not delete them from the server as that is a seperate command and only notify if the last one has changed.
                      John
                      Added, sending a list command on the highest number and looking for a size change is probably the fastest.
                      Last edited by John Petty; 26 Apr 2009, 12:16 AM.

                      Comment


                      • #12
                        Please only use secure connections checking POP3.
                        https://duckduckgo.com instead of google

                        Comment


                        • #13
                          Fairer statement than in other thread, but still necro-posting
                          Dale

                          Comment


                          • #14
                            I don't find anything wrong telling people they are at risk using this code (it is not using a secure connection with Pop3.)
                            I haven't found any evidence that IMAP is more secure checking for email than Pop3 if both are using TLS.
                            The code above is insecure.
                            Last edited by Mike Doty; 10 Jun 2019, 04:35 PM.
                            https://duckduckgo.com instead of google

                            Comment

                            Working...
                            X