Wednesday, October 19, 2016

ESP8266 Gmail Send Email

Found this sweet Instructable http://www.instructables.com/id/ESP8266-GMail-Sender/ detailing how to cook up a Gmail Sender using the ESP8266. So I hooked it up with a temperature sensor and started testing sending notifications based on various temperatures.

Create a new Gmail Account


I created a new account because you have to enable less secure apps access on Gmail.
  1. Create your account and then go to Gmail. 
  2. Go to https://myaccount.google.com. 
  3. You should land on the settings for your new google account. 
  4. Click the Signing into Google Link
  5. Enable the Allow Less Secure Apps option at the bottom of the page.
  6. You google account should be all set

Update the Code


I had some trouble connecting the ESP to the Arduinio IDE at first. I followed several different tutorials online. There are some good detailed tutorials about how to add the board to the IDE and such. I think the final fix was a full reboot of my Desktop. It just magically started working. Perhaps I can cover that in a future blog post, but for now I am just going to assume you have your ESP working with the Arduino IDE.


  1. Go snag the original ZIP file from the Instructable link above or go here to snag a copy of the zip file.
  2. Open the Gsender.h in the Arduino IDE
  3. Near the top of the file you need to provide your new Gmail Login and Password in BASE64 format. Go to this website: https://www.base64encode.org/ and paste your login to convert it to BASE64 and then convert your password to BASE64
  4. Change the FROM address to your new Gmail address
  5. Save this file
So this project will read the temperature from a temperature sensor and then will send an email if the temperature is within a specific threshold. I modified the code on the original Instructable page to enable it to read the sensor and send the email. You may want to work with the original code from the Instructable before moving on. This will ensure the core functionality (wifi connecting and email sending) is working before moving on to sensor reading.
  1. Open the ESP8266_Gmail_Sender file in the Arduino IDE
  2. I have pasted my Sender file below. This file will connect to your WiFi and then will read a temperature sensor every 30 seconds. If the temperature falls within a defined threshold it will send an email.
  3. Save this file
  4. Compile and upload the sketch

Output and Email


If all goes well the sketch will upload and compile. You will start seeing temperature readings in the Serial Monitor output. You will also see a connection to Gmail if the temperature falls within your defined range.





5 comments:

  1. Nice write up! What temp sensor were you using for this project? Since you were doing an analogRead of the voltage drop across the pin, I am guessing it was either a generic thermistor/resistor combo or NTC 10K.

    ReplyDelete
  2. Just a generic Temp Sensor I received with the Arduino SparkFun Inventors Kit.

    ReplyDelete
  3. Link to Temp Sensor: https://www.sparkfun.com/products/10988

    ReplyDelete
  4. I would really love to getting this to work, but I keep getting this in my serial monitor:
    Connection: ESTABLISHED
    Got IP address: 192.168.1.50
    71.26
    220 smtp.gmail.com ESMTP k203sm19030952oia.28 - gsmtp

    502 5.5.1 Unrecognized command. k203sm19030952oia.28 - gsmtp

    Error sending message: identification error

    The 71.26 is the temperature I am reading and trying to email. Can someone shed some light on what I might be doing wrong?

    ReplyDelete