send email

I found this code on Playground but I have been testing no good results , may be, anyone knows where is the mistake or where I can find another code

thanks

/*
   Email client sketch for IDE v1.0.1 and w5100/w5200
   Posted December 2012 by SurferTim
*/

#include <SPI.h>
#include <Ethernet.h>

// this must be unique
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0x5C, 0x18};  
// change network settings to yours
IPAddress ip( 192, 168, 1, 10 );    
IPAddress gateway( 192, 168, 1, 1 );
IPAddress subnet( 255, 255, 255, 0 );

// change server to your email server ip or domain
IPAddress server( 173,194,37,117 );
//char server[] = "ekarduino001@gmail.com";

EthernetClient client;

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, subnet);
  delay(2000);
  Serial.println(F("Ready. Press 'e' to send."));
}

void loop()
{
  byte inChar;

  inChar = Serial.read();

  if(inChar == 'e')
  {
      if(sendEmail()) Serial.println(F("Email sent"));
      else Serial.println(F("Email failed"));
  }
}

byte sendEmail()
{
  byte thisByte = 0;
  byte respCode;

  if(client.connect(server,25)) {
    Serial.println(F("connected"));
  } else {
    Serial.println(F("connection failed"));
    return 0;
  }

  if(!eRcv()) return 0;
  Serial.println(F("Sending helo"));

// change to your public ip
  client.println(F("helo 173.194.37.117"));

  if(!eRcv()) return 0;
  Serial.println(F("Sending From"));

// change to your email address (sender)
  client.println(F("MAIL From: ekarduino001@gmail.com"));

  if(!eRcv()) return 0;

// change to recipient address
  Serial.println(F("Sending To"));
  client.println(F("RCPT To: ekarduino002@gmail.com"));

  if(!eRcv()) return 0;

  Serial.println(F("Sending DATA"));
  client.println(F("DATA"));

  if(!eRcv()) return 0;

  Serial.println(F("Sending email"));

// change to recipient address
  client.println(F("To: ekarduino002@gmail.com"));

// change to your address
  client.println(F("From: ekarduino001@gmail.com"));

  client.println(F("Subject: Arduino email test\r\n"));

  client.println(F("This is from my Arduino!"));

  client.println(F("."));

  if(!eRcv()) return 0;

  Serial.println(F("Sending QUIT"));
  client.println(F("QUIT"));

  if(!eRcv()) return 0;

  client.stop();

  Serial.println(F("disconnected"));

  return 1;
}

byte eRcv()
{
  byte respCode;
  byte thisByte;
  int loopCount = 0;

  while(!client.available()) {
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 20000) {
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return 0;
    }
  }

  respCode = client.peek();

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  if(respCode >= '4')
  {
    efail();
    return 0;  
  }

  return 1;
}


void efail()
{
  byte thisByte = 0;
  int loopCount = 0;

  client.println(F("QUIT"));

  while(!client.available()) {
    delay(1);
    loopCount++;

    // if nothing received for 10 seconds, timeout
    if(loopCount > 20000) {
      client.stop();
      Serial.println(F("\r\nTimeout"));
      return;
    }
  }

  while(client.available())
  {  
    thisByte = client.read();    
    Serial.write(thisByte);
  }

  client.stop();

  Serial.println(F("disconnected"));
}

I found this code on Playground but I have been testing no good results

Maybe your network settings are not correct.
Maybe the email server ip is not correct.
Maybe the "from" email address domain does not exist.
Maybe the "to" email address doesn't exist.
Maybe the "to" email domain is not handled by that server.
Maybe your ISP blocks port 25 to other servers but theirs.
Maybe the email server won't take your email because you have a non-commercial account.
Maybe you are on a spam block list.

Would you mind sharing the results when you try to send? That could help decide which of those is the problem.

The server has to be the smtp server, not your email.
I think I used this: server[] = "smtp.gmail.com";

When using Ethernet.begin with only the 'mac', the DHCP is used. The router will give the Arduino a (local) IP number.

Ethernet.begin(mac);

Your internet IP number is the same the the server IP number in the sketch. That's not right. Use an online service to find your internet IP, like this one:

Erdin:
The server has to be the smtp server, not your email.
I think I used this: server[] = "smtp.gmail.com";

When using Ethernet.begin with only the 'mac', the DHCP is used. The router will give the Arduino a (local) IP number.

Ethernet.begin(mac);

Your internet IP number is the same the the server IP number in the sketch. That's not right. Use an online service to find your internet IP, like this one:
http://www.whatismyip.com/

You are not aiming that at me, are you? That is not what I asked you to post.

Didn't you notice? I'm the author of that code.

SurferTim, didn't you notice ? I replied together with you in other topic about your email sketch.
http://forum.arduino.cc/index.php?topic=185061.msg1371325#msg1371325
I was looking so long for a sketch like that, I'm very grateful for your sketch.

I was aiming at EJTR, I noticed that the IP of the SMTP server was the same as his own global internet IP. A string will be resolved normally in most cases for the SMTP server. And I think DHCP is a lot easier.

@Erdin: My bad and apology. :blush:

It's okay, I was being cheesy :wink: