Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By asmallri
#39795
Erni wrote:Hi,
I have used this Arduino example on a Esp8266-01.
I made a few changes but it works as expected and sends mail without problems.

http://playground.arduino.cc/Code/Email?action=sourceblock&num=2

If you have trouble with this, I will try to find the sketch again, and post it here.


Hi Erni,

If you find the sketch, could you post it?
User avatar
By Erni
#39817 Hi asmallri,

This is the sketch:

Code: Select all#include <ESP8266WiFi.h>
const char* SSID = "SSID";
const char* PASS = "pass";
char server[] = "mail.smtpcorp.com";

WiFiClient client;
void setup()
{
  Serial.begin(115200);
  delay(10);
  Serial.println("");
  Serial.println("");
  Serial.print("Connecting To ");
  Serial.println(SSID);
  WiFi.begin(SSID, PASS);

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi Connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  byte ret = sendEmail();
}

void loop()
{
}

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

  if (client.connect(server, 2525) == 1) {
    Serial.println(F("connected"));
  } else {
    Serial.println(F("connection failed"));
    return 0;
  }
  if (!eRcv()) return 0;

  Serial.println(F("Sending EHLO"));
  client.println("EHLO www.example.com");
  if (!eRcv()) return 0;
  Serial.println(F("Sending auth login"));
  client.println("auth login");
  if (!eRcv()) return 0;
  Serial.println(F("Sending User"));
  // Change to your base64, ASCII encoded user
  client.println("xxxxxx"); //<---------User
  if (!eRcv()) return 0;
  Serial.println(F("Sending Password"));
  // change to your base64, ASCII encoded password
  client.println("yyyyyyyy");//<---------Passw
  if (!eRcv()) return 0;
  Serial.println(F("Sending From"));
  // change to your email address (sender)
  client.println(F("MAIL From: cccc@gmail.com"));
  if (!eRcv()) return 0;
  // change to recipient address
  Serial.println(F("Sending To"));
  client.println(F("RCPT To: xxx@yormai.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:  xxx@yormai.com"));
  // change to your address
  client.println(F("From: yyyyy@gmail.com"));
  client.println(F("Subject: Esp8266 email test\r\n"));
  client.println(F("This is from my ESP8266\n"));
  client.println(F("This is line 2 from my ESP8266"));
  client.println(F("This is line 3 from my ESP8266"));

  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 > 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;
}
User avatar
By picstart
#39825 Worked perfectly once specific user names passwords in base64 ( web app does the translation into base 64) and smtp server and port are entered.
It is always a good thing when working code is posted...thank you.
I am getting some soft failure messages from my email service provider but it seems to work just fine.
User avatar
By RainerOchs
#39887 Yes works great! Thanks. This was the missing part of code I was looking for.

I am currently building a flooding alarm - if the floor is flooded by water I want to have an email / SMS alert. The device will be in deep sleep most of the time, the water sensor will trigger the reset. From there on the device is activated and sends the mail. My mail provider will alert me of the mail by an SMS.

It takes about one minute from start to recipt of email what is fine for alarm applications.
As the device is in deep sleep at below 20µA the battery will last forever.

Rainer