POP3 library

To use the pop3 library, you also need to follwing dependencies:

The basic code for reading mails looks like this:

#include "EthernetNetIf.h"

#include "mbed.h"

#include "pop3.h"

main()
{
    EthernetNetIf eth;
    EthernetErr ethErr;
    printf("Setting up...\n");
    do {
        ethErr = eth.setup();
        if (ethErr) printf("waiting for network...\n", ethErr);
    } while (ethErr != ETH_OK);

    Pop3 *p3=new Pop3("mail.server","mail.user","mail.password");
    
    bool r=p3->init();
    
    printf("init ok=%i\n",r);
    
    if(r)
    {
        list<string> *ids=p3->getMessages();
        list<string>::iterator it;
        for ( it=ids->begin() ; it != ids->end(); it++ )
        {
            printf("id=%s\n",(*it).c_str());
            
            Pop3Message *msg=p3->getMessage(*it);
            if (NULL==msg)
                continue;
            printf("from %s\n",msg->from.c_str());
            printf("subj %s\n",msg->subject.c_str());
            
            p3->deleteMessage(*it);
            
            delete msg;
            
        }
        delete ids;
    }
    p3->close();
    delete p3;
}

Connection to the POP3 server is done with the init() call. After that, one can retrieve a list of message IDs (which are normally starting with 1, and might be renumbered for the next session). With a message ID one can retrieve a message, or delete it. In the retrieved message the UID of the message as given by the server is stored, but not the retrieval ID.

Note that one needs to delete all objects returned by the POP3 class, this is not handled by the library.


7 comments on POP3 library:

25 Apr 2011

I've managed to get this sample working - great work on the library. It does timeout quite a lot - I don't think it's always my Internet connection:

error - could not connect (timeout) init ok=0 error while receiving data: -65531!

Thanks, Tony.

15 Aug 2011

Hello:

Do you have a sample program as an import? I am a bit fuzzy on this and would like to start working with a functioning program if possible.

Hopefully you have one!

Thanks for your help!

Cheers,

Steve

16 Aug 2011

Steve D wrote:

Do you have a sample program as an import?

No, not now. But I have extended to sample code to form a complete program, so you can use copy&paste.

11 Apr 2012

Tony Mudd wrote:

I've managed to get this sample working - great work on the library. It does timeout quite a lot - I don't think it's always my Internet connection:

error - could not connect (timeout) init ok=0 error while receiving data: -65531!

Thanks, Tony.

Steve D wrote:

Hello:

Do you have a sample program as an import? I am a bit fuzzy on this and would like to start working with a functioning program if possible.

Hopefully you have one!

Thanks for your help!

Cheers,

Steve

11 Apr 2012

I've a same problem with library pop3. error - could not connect (timeout) init ok=0 error while receiving data: -65531!

I need help, do you have a sample program as an import?

thanks

11 Apr 2012

Error -65531 is 0xFFFB, which is defined by the TCPSocket class as

TCPSOCKET_MEM, ///<Not enough mem

(it is just reached through by the TCPLineStream class) One of the reasons might be that the mail you want to receive is too large (after all, you can handle maybe 10k or so). I have never seen this error, I worked only with small text messages (and when I had memory usage problems, the mbed always crashed before).

If this isn't the case, you might want to try to use the original NetServices library instead of NetServicesMin (I haven't it updated in a long time, so the original one might contain bugfixes).

You also can enable the commented-out print on line 179 of tcplinestream.cpp - this will then print everything it receives to the mbed console.

11 Apr 2012

I added a demo program which can be imported - just don't forget to change the data for accessing your mail server. Note I didn't test it though, I just compiled it :)

Please log in to post comments.