Arduino send email error in documentation


hello,

there error in code snippet 1 @ https://playground.arduino.cc/code/email

the code send "auth login" command missing in code snippet 1 @ above link. while executing code, got " 500 - unrecognized command" smtp server.

the correct working code below:

/*
   email client sketch ide v1.0.5 , w5100/w5200
   posted 7 may 2015 surfertim
*/
 
#include <spi.h>
#include <ethernet.h>
 
// must unique
byte mac[] = { 0x90, 0xa2, 0xda, 0x00, 0x59, 0x67 }; 
// change network settings yours
ipaddress ip( 192, 168, 2, 2 );   
ipaddress gateway( 192, 168, 2, 1 );
ipaddress subnet( 255, 255, 255, 0 );
// server smtpout.secureserver.net
char server[] = "your smtp server address";
int port = 25;
 
ethernetclient client;
 
void setup()
{
  serial.begin(9600);
  pinmode(4,output);
  digitalwrite(4,high);
  ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  serial.println(f("ready. press 'e' 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,port) == 1) {
    serial.println(f("connected"));
  } else {
    serial.println(f("connection failed"));
    return 0;
  }
 
  if(!ercv()) return 0;
 
  serial.println(f("sending hello"));
// replace 1.2.3.4 arduino's ip
  client.println("ehlo 1.2.3.4");
  if(!ercv()) return 0;

  serial.println(f("sending auth login"));
  client.println("auth login");
  if(!ercv()) return 0;
 
  serial.println(f("sending user"));
 // change base64 encoded username of sender's email address
   client.println("your base64 encoded sender's email address/username");
 
 
  if(!ercv()) return 0;
 
  serial.println(f("sending password"));
// change base64 encoded password of sender's email address.
  client.println("your base64 encoded sender's password");
   
 
  if(!ercv()) return 0;
 
// change email address (sender)
  serial.println(f("sending from"));
  // enter appropriate email address.
  client.println("mail from: <sender@somedomain.com>");
  if(!ercv()) return 0;
 
// change recipient address
  serial.println(f("sending to"));
  // enter appropriate email address.
  client.println("rcpt to: <receiver@somedomain.com>");
  if(!ercv()) return 0;
 
  serial.println(f("sending data"));
  client.println("data");
  if(!ercv()) return 0;
 
  serial.println(f("sending email"));
 
 // change recipient address
  //enter appropriate email address.
  client.println("from: me <sender@somedomain.com>");

 
// change address . enter appropriate email address.
  client.println("to: nobody <receiver@somedomain.com>");
 
  client.println("subject: arduino email test\r\n");
 
  client.println("this arduino!");
 
  client.println(".");
 
  if(!ercv()) return 0;
 
  serial.println(f("sending quit"));
  client.println("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 10 seconds, timeout
    if(loopcount > 10000) {
      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 10 seconds, timeout
    if(loopcount > 10000) {
      client.stop();
      serial.println(f("\r\ntimeout"));
      return;
    }
  }
 
  while(client.available())
  { 
    thisbyte = client.read();   
    serial.write(thisbyte);
  }
 
  client.stop();
 
  serial.println(f("disconnected"));
}

please correct above page in documentation.

thanks!

i don't know talking about. code in playground (for smtp2go section):
code: [select]
  serial.println(f("sending auth login"));
  client.println("auth login");
  if(!ercv()) return 0;

  serial.println(f("sending user"));
// change base64 encoded user
  client.println("xxxx");

  if(!ercv()) return 0;

  serial.println(f("sending password"));
// change base64 encoded password
  client.println("yyyy");

  if(!ercv()) return 0;

the first example not need auth login.


Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Arduino send email error in documentation


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???