[SOLVED] Working Email sketch for esp8266

Hello all, I am new to this. I am using an ESP8266 - 12e and it works great with the standalone, Now i want to get a working Emailer setup on one of them. The plan is to put a PIR in my garage, and every time someone is in there it will email me. are there working examples out there ?
thanks

Hello. You need simply call Blynk.email. Docs.

Thanks Dmitriy, I tried the following code. It gets an error when compiling "
exit status 1
‘emailOnButtonPress’ was not declared in this scope`

/**************************************************************

  • Blynk is a platform with iOS and Android apps to control
  • Arduino, Raspberry Pi and the likes over the Internet.
  • You can easily build graphic interfaces for all your
  • projects by simply dragging and dropping widgets.
  • Downloads, docs, tutorials: http://www.blynk.cc
  • Blynk community: http://community.blynk.cc
  • Social networks: http://www.fb.com/blynkapp
  •                           http://twitter.com/blynk_app
    
  • Blynk library is licensed under MIT license
  • This example code is in public domain.

  • This example runs directly on ESP8266 chip.
  • You need to install this for ESP8266 development:
  • https://github.com/esp8266/Arduino
  • Please be sure to select hte right ESP8266 module
  • in the Tools -> Board menu!
  • Change WiFi ssid, pass, and Blynk auth token to run :slight_smile:

**************************************************************/

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “YourAuthToken”;

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, “ssid”, “pass”);
while (Blynk.connect() == false) {
// Wait until connected
}

// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient’s “e-mail address”, “Subject” and the “message body”
Blynk.email("your_email@mail.com", “Subject”, “My Blynk project is online.”);

// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}

void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER MINUTE! ***

// Let’s send an e-mail when you press the button
// connected to digital pin 2 on your Arduino

int isButtonPressed = !digitalRead(2); // Invert state, since button is “Active LOW”

if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
BLYNK_LOG(“Button is pressed.”); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", “Subject: Button Logger”, “You just pushed the button…”);

}
}

void loop()
{
Blynk.run();
}

You don’t need to use exactly this sketch. It is just example as you have ESP8266. Just add email command within your ESP code, that’s it.

@ryan_blynk with the very latest Arduino / ESP8266 the functions need to be in a SPECIFIC order so move void emailOnButtonPress() function before void setup(). It should then compile.

I did that, now it is telling me

Arduino: 1.6.7 (Windows 10), Board: “Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck”

ESP8266_email_1:38: error: expected constructor, destructor, or type conversion before ‘(’ token

pinMode(2, INPUT_PULLUP);

      ^

ESP8266_email_1:40: error: expected constructor, destructor, or type conversion before ‘(’ token

 attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);

                ^

C:\Users\ryanm\Desktop\ESP8266_email_1\ESP8266_email_1.ino: In function ‘void emailOnButtonPress()’:

ESP8266_email_1:76: error: a function-definition is not allowed here before ‘{’ token

{

^

ESP8266_email_1:78: error: expected ‘}’ at end of input

}

^

exit status 1
expected constructor, destructor, or type conversion before ‘(’ token

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

/**************************************************************

  • Blynk is a platform with iOS and Android apps to control
  • Arduino, Raspberry Pi and the likes over the Internet.
  • You can easily build graphic interfaces for all your
  • projects by simply dragging and dropping widgets.
  • Downloads, docs, tutorials: http://www.blynk.cc
  • Blynk community: http://community.blynk.cc
  • Social networks: http://www.fb.com/blynkapp
  •                           http://twitter.com/blynk_app
    
  • Blynk library is licensed under MIT license
  • This example code is in public domain.

  • This example runs directly on ESP8266 chip.
  • You need to install this for ESP8266 development:
  • https://github.com/esp8266/Arduino
  • Please be sure to select hte right ESP8266 module
  • in the Tools -> Board menu!
  • Change WiFi ssid, pass, and Blynk auth token to run :slight_smile:

**************************************************************/

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = “YourAuthToken”;

// Setting the button
pinMode(2, INPUT_PULLUP);
// Attach pin 2 interrupt to our handler
attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);

void setup()
{
Serial.begin(9600);
Blynk.begin(auth, “ssid”, “pass”);
while (Blynk.connect() == false) {
// Wait until connected
}

// Send e-mail when your hardware gets connected to Blynk Server
// Just put the recepient’s “e-mail address”, “Subject” and the “message body”
Blynk.email("your_email@mail.com", “Subject”, “My Blynk project is online.”);

}

void emailOnButtonPress()
{
// *** WARNING: You are limited to send ONLY ONE E-MAIL PER MINUTE! ***

// Let’s send an e-mail when you press the button
// connected to digital pin 2 on your Arduino

int isButtonPressed = !digitalRead(2); // Invert state, since button is “Active LOW”

if (isButtonPressed) // You can write any condition to trigger e-mail sending
{
BLYNK_LOG(“Button is pressed.”); // This can be seen in the Serial Monitor
Blynk.email("your_email@mail.com", “Subject: Button Logger”, “You just pushed the button…”);

}

void loop()
{
Blynk.run();
}

@ryan_blynk are your two include’s as shown below as they are invisible if you don’t format the sketch with the </> icon?

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

Think you messed up when you moved the function but without the sketch being formatted it is hard to tell. This is what you need, compiles fine.

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

void emailOnButtonPress()
{
  // *** WARNING: You are limited to send ONLY ONE E-MAIL PER MINUTE! ***

  // Let's send an e-mail when you press the button
  // connected to digital pin 2 on your Arduino

  int isButtonPressed = !digitalRead(2); // Invert state, since button is "Active LOW"

  if (isButtonPressed) // You can write any condition to trigger e-mail sending
  {
    BLYNK_LOG("Button is pressed."); // This can be seen in the Serial Monitor
    Blynk.email("your_email@mail.com", "Subject: Button Logger", "You just pushed the button...");

  }
}


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "ssid", "pass");

  while (Blynk.connect() == false) {
    // Wait until connected
  }

  // Send e-mail when your hardware gets connected to Blynk Server
  // Just put the recepient's "e-mail address", "Subject" and the "message body"
  Blynk.email("your_email@mail.com", "Subject", "My Blynk project is online.");

  // Setting the button
  pinMode(2, INPUT_PULLUP);
  // Attach pin 2 interrupt to our handler
  attachInterrupt(digitalPinToInterrupt(2), emailOnButtonPress, CHANGE);
}

void loop()
{
  Blynk.run();
}
2 Likes

Thank you it works great now.