Email not working on ESP8266

I am trying the example email notifier and haven’t had any luck in getting it to work. I’ve tried my main email (herb@hwblair.com) and my alternate, without any success.
any help would be appreciated.


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

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

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("herb_blair@yahoo.com", "Subject: Test", "Test Email");

  }
}


void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "MYSSID", "MYPASSword");

  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("herb_blair@yahoo.com", "test", "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();
}

Please post your code using the proper format. It makes it easier for us to troubleshoot. Thanks.

1 Like

Make sure you have the email widget in your app and are not sending an email more then once every 15 seconds. You could be getting button bounce causing multiple email attempts?

This is what I see on the monitor:


/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
/
//_, /////_
/
__/ v0.4.6 on NodeMCU

[10062] Connecting to blynk-cloud.com:8442
[10226] Ready (ping: 0ms).
[15227] Connecting to blynk-cloud.com:8442
[15345] Ready (ping: 0ms).
[15412] Button is pressed.
[20346] Connecting to blynk-cloud.com:8442
[20535] Ready (ping: 0ms).

Did you add email widget in app?

only one attempt

You are constantly disconnecting… probably due to the repetitive email attempts. Look for button debouncing solutions (Google button debounce) to implement into your sketch.

yes

Ok. So look like @Gunner is right and this is debouncing issue / wiring issue. As ESP disconnects right after connection.

this construction is not necessary anymore.

OK, I stripped out the button stuff, and put in a flag.
if (flag == 0){

Blynk.email("herb@hwblair.com", “test”, “My Blynk project is online.”);
flag =1;
}
the above is in setup.

still no email.

Are you on the Blynk Cloud or Local server? EDIT - sorry, I wasn’t paying attention :stuck_out_tongue: you are on Cloud, so my next question is irrelevant.

However, even a flag like that will not stop a physical button on an interrupt from “bouncing” and running the loop multiple times a second.

@Herb_Blair Your code looks different than the example on the sketch builder, very close, but still different. Try using it as is, and just put your email, wifi information and auth token in the appropriate places.

I’m not using any of the button code.
in set up I check for the flag, if not set then I send the email and set the flag
if set, do nothing.
that’s about as simple as I can get it.

Could you re-post the code you are using then. Or edit your original post to reflect what you are running.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
int flag =0;
char auth[] = "39adf76e005745f49593e58c469dc323";

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, "SSID", "PASSWORD");

  
if (flag == 0){
  
  Blynk.email("herb@hwblair.com", "test", "My Blynk project is online.");
flag =1;
}
}
void loop()
{
  Blynk.run();
}

Use backtick keys, not commas or apostrophes for formatting code. I have fixed your post, please look back at it (edit) to see how it is done. Thanks.

OK.
I changed board to an Adafruit ESP8266 and my code works.

don’t understand why it won’t work with a ESP8266 12E Dev Module.

Problem with the flashing maybe ?

Just tested your code and it works on my NodeMCU Dev board.

Problem with the board or his settings in Arduino IDE ?