Error EmailPOP3 Reader

Hi!

I'm trying a sketch EmailPOP3 reader found in Arduino playground. But, apparently, I keep received an error : "Email POP3 failed, error = -200" when I'm trying to check my email .

I dont really understand the source of the error.

Could anyone who had tried this sketch help me?

The sketch that i'm trying : Arduino Playground - EmailPOP3

Thank u!

This is the sketch I'm trying to execute :

#include <SPI.h>
#include <Ethernet.h>
 
 
// Use comments to enable or disable this define for debug messages
#define DEBUG_POP
 
// Use comments to enable or disable the deleting of the mail
//#define ENABLE_DELETE_POP
 
 
// The mac address must be an unique number
// A mac generator is used:
//   http://www.miniwebtool.com/mac-address-generator/
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0xFD, 0x78 };  
// change network settings to yours
IPAddress ip( 192, 168, 10, 50 );    
IPAddress gateway( 192, 168, 10, 210 );
IPAddress subnet( 255, 255, 255, 0 );
 
 
// Set the server POP3 address, the port, the user and password.
// The POP3 mail server is something like this:
//     mail.yourdomain.com, pop.yourdomain.com, pop3.yourdomain.com
// Using PROGMEM for these causes a fail when trying to connect and log in.
const char pop_server[] = "pop.gmail.com";
const int  pop_port = 110;
const char pop_user[] = "username";
const char pop_pass[] = "xxxx";
 
 
// The number of milliseconds timeout for parseInt() and find().
// The response time for the Server can still be 10 seconds.
#define POP_TIMEOUT 10
#define POP_TIMEOUT_DEFAULT 1000
 
 
EthernetClient client;
 
 
void setup()
{
  Serial.begin( 9600);
  Serial.println(F( "\nArduino POP3 email reader"));
 
  pinMode( 13, OUTPUT);     // the system led is used for testing
 
  // When the Ethernet Shield is used, there is also a SD card connected
  // to the SPI bus. Disable the SD card with chip select at pin 4.
  pinMode( 4, OUTPUT);
  digitalWrite( 4, LOW);
 
 
  // Start Ethernet. Use only the 'mac' parameter for DHCP
  // Use 'mac' and 'ip' parameters for static IP address.
   Ethernet.begin( mac, ip);
   Ethernet.begin( mac, ip, gateway, gateway, subnet);
//  if( Ethernet.begin( mac) == 0)
//  {
//    Serial.println("Failed to configure Ethernet using DHCP.");
//    // no point in carrying on, so do nothing forevermore:
//    while(1);
//  }
// 
  // print your local IP address.
  Serial.println(F( "Ethernet started."));
  Serial.print(F( "Local IP = "));
  Serial.println(Ethernet.localIP());
 
  Serial.println(F( "Press 'c' to check mail."));
}
 
 
void loop()
{
  // Create a buffer to receive the commands in (that is the Subject of the mail).
  char buffer[32];
 
  byte inChar = Serial.read();
  if(inChar == 'c')
  {
    // The getEmail gets the text of the mail Subject into the buffer.
    // The valid number of received characters are returned.
    // If the return value is < 0, it is an error.
    int n = getEmail( buffer, sizeof(buffer));
 
    if( n<0)
    {
      Serial.print(F("Email POP3 failed, error = "));
      Serial.println( n);
    }
    else
    {
      if( n == 0)
      {
        Serial.println(F("Ready, nothing to do."));
      }
      else
      {
        // 'n' is > 0, a command received.
        Serial.print(F("Email checked, Command = \""));
        Serial.print( buffer);
        Serial.println(F("\""));
 
 
        // Check the commands.
        //
        // At this moment, a single command 'L' is used to set system led on or off.
        //    L=1   (set led on)
        //    L=0   (set led off)
        if( buffer[0] == 'L' && buffer[1] == '=')
        {
          digitalWrite( 13, buffer[2] == '0' ? LOW : HIGH);
        }
      }
    }
  }
}
 
 
// getEmail
// --------
// Find an email on a mail server, using POP3.
// The Subject should start with "ARDUINO " and the text
// after that is copied into pBuf.
//
// The data in pBuf is only valid if the return value is not an error
// (an error is return value less than zero).
//
int getEmail( char *pBuf, int nBufSize)
{
  // nBytes is the number of bytes that is returned by getEmail.
  int nBytes = 0;
 
  // Connect to server
  // client.connect returns '1' if okay, or negative number if error.
  //    SUCCESS 1
  //    0     (error, unknown timeout, perhaps an error in the library)
  //    TIMED_OUT -1
  //    INVALID_SERVER -2
  //    TRUNCATED -3
  //    INVALID_RESPONSE -4
  //    -5    (there is no mail server at that IP address and port)
  // The string for the server must be a normal string in sram, no PROGMEM allowed.
  int nError = client.connect( pop_server, pop_port);
 
  // During testing, a value of zero was sometimes returned.
  // This is not according to the documentation and it is an error.
  // Therefor the non-error value '0' is turned into a negative number to
  // indicate an error.
  if( nError == 0)
    return( -200);
 
  // Only a value of 1 is okay.
  if( nError != 1)
    return( nError);
 
#ifdef DEBUG_POP
  Serial.println(F("connected"));
#endif
  // Start Ethernet. Use only the 'mac' parameter for DHCP
  // Use 'mac' and 'ip' parameters for static IP address.
   Ethernet.begin( mac, ip);
   Ethernet.begin( mac, ip, gateway, gateway, subnet);

Read the comments again. You should have ONE call to begin().

Hi rasah,
I can't say anything about your code, but from my experience with gmail you can't simply pull mails via POP3 from gmail. You have to activate the use of POP3 in your gmail-account, and even then you can only connect to Port 995 with SSL.
Even with this it's not garanteed to get mails, because gmail will see your Arduino as a new device that hasn't connected before and has to be allowed.

I would suggest using a different mailprovider for testing.

Greetings,
Zuujin

Thank u zuujin and PaulS!

Zuujin : How to activate the use of POP3 in the mail provider?

Thank u!

Zuujin : How to activate the use of POP3 in the mail provider?

If you are still referring to gmail, forget it. gmail's pop3 server requires SSL for communication, which is beyond the Arduino's capabilities.

Thank u PaulS for the response!

I will try with other email provider or anyone know the email provider that can work with Arduino?

thank u!

www.inbox.com works. So does my ISP's POP3 server. Maybe your ISP's email server works ok.

A return value of -200 is due to the client being unable to connect to the server.

  // During testing, a value of zero was sometimes returned.
  // This is not according to the documentation and it is an error.
  // Therefor the non-error value '0' is turned into a negative number to
  // indicate an error.
  if( nError == 0)
    return( -200);

edit: The only success return value is 1. Anything else is an error.

Thank u surferTim. But unfortunately, Inbox.com webmail is currently being prepared for a major system upgrade. :frowning:

rasah:
Thank u surferTim. But unfortunately, Inbox.com webmail is currently being prepared for a major system upgrade. :frowning:

That is a problem. I wonder how the system upgrade is going to affect the POP3 server? I just checked my POP3 client code. It connected and read my email.

Do you have an email server provided by your ISP? I use Cox Communications, and their email servers work ok.

You can't use any email servers that require TLS or SSL. The Arduino library can't do that.