ESP8266 GMail Sender





Introduction: ESP8266 GMail Sender

Hello and welcome to my first Instructable.

I will show you how to send emails from any ESP8266 wifi module using Gmail server.

This instructable relies on Arduino core for ESP8266 WiFi chip,

which makes a self-contained microcontroller from it (no need of AT commands and master devices).

You can connect sensors and get notified by email about changes.

Before we begin

Required hardware:

  1. Any ESP8266 (I'm using ESP8266-07 ebay link).
  2. In my case USB UART Board(I'm using FT232RL FTDI Serials Adapter Module ebay). Not needed if your board has usb port.
  3. Some jumper cables.
  4. WIFI router of course.

List may be incomplete.

Required software:

  1. Arduino Software
  2. Arduino core for ESP8266 WiFi chip
  3. Sketch with project and test code (

Step 1: Gmail Account Setup

We are going to use SMTP to send messages.

Using SMTP Authentication we provide only email and password,

by default Google uses more complex verification methods so we need to change settings.

Go to your Google account settings and enable "Allow less secure apps" at the bottom of the page.

This mean apps only need your email and password when login to your gmail account.

If you concerned about security, just use different account.

Step 2: Edit Sketch

I wrote a little sketch which send one test message to check if all works as should.

When all software downloaded and installed:

  • Unzip
  • Find and open ESP8266_Gmail_Sender.ino
  • Set your wifi access point name (SSID) and password. Should be like this:
const char* ssid = "MyWiFi";
const char* password = "12345678";
  • In setup() function find
if(gsender->Subject(subject)->Send("", "Setup test"))

First parameter of Send() function is recipient email, second message text.

Change recipient from to your email which will receive a message.

I'm receiving many emails every day because some of You guys not attentive, PLEASE DON'T FORGET TO CHANGE RECIPIENT EMAIL!

Subject function is optional! Subject sets once and stored until you change it.

You can send mails without subject or if it already set

gsender->Send(to, message);
  • Now open Gsender.h tab
  • We need Base64 encoded email address and password of gmail account which will be used to send emails.

You can use for encoding, result must be something like:

const char* EMAILBASE64_LOGIN = "Y29zbWkxMTExMUBnbWFpbC5jb20=";
  • Now set FROM field.
const char* FROM = "";

That`s all for this part.

Step 3: Code Uploading and Testing

Save changes. Don`t forget to set your board in Tool menu.

Upload sketch to your ESP8266 board.

Open Serial monitor, board will print log messages.

That`s all I hope you will receive "Message send.". Thanks...

10 People Made This Project!


  • Woodworking Contest

    Woodworking Contest
  • Microcontroller Contest

    Microcontroller Contest
  • Make it Move Contest

    Make it Move Contest

We have a be nice policy.
Please be positive and constructive.


3 Questions


I have arduino mega2560 and ESP8266 with ESP-01.

When attaching ESP-01 on arduino

RX ------ RX

TX ------- TX

VCC ----- 5V

GND ----- GND

after uploading will maked a error:

warning: espcomm_sync failed

error: espcomm_open failed

error: espcomm_upload_mem failed

error: espcomm_upload_mem failed

What should I do?

Thank you.


connect GPI0 to ground and also connect Reset pin of Arduino to ground. Hope this helps.

Has anyone tried using this Gmail email sender with EthernetClient? I have tried using it but it does not get out of the while loop in !AwaitSMTPResponse(client, "235"). For some reason client.available() is never true and this gets into an infinite while loop. Any help would be greatly appreciated.

how can I pass the change of sensors to the e-mail.

is there a sample code. (push button open / closed).

Thank you

"Google translator"


I have succeeded according to your guidance.

Now I want to add the warning, for example when the signal level 1 from the sensor to send gmail then how?

thank you

Estupendo trabajo. Lo conocí mediante otro usuario en Youtube, indagué un poco y di con su creador. Enhorabuena. Me ha venido de maravilla para mi proyecto de alarma. Gracias.

I had done all the instructions given above. Connection established getting IP address. But finally getting

220 ESMTP a9sml4857646pfe.147 - gsmtp

502 5.5.1 Unrecognized command. a9sml4857646pfe.147 - gsmtp

Error Sending message : identification error.

Please Help Me

Hi, great code but i have a little problem

I´m using a wemos lolin esp32 oled but the serial monitor give this error: Error sending message: Sending message error

Any idea about that error?


P.D. I didn´have the ESP8266WiFi.h library so i used WiFi.h

6 replies

Hello. Gsender rely on libraries from Arduino Esp8266 core, it won't work with WiFi.h

Borya, I would like to follow up with my experience with your code and the ESP32 in particular the M5Stack. Turning on debugging everything seems to work until we get to the part

354 Go ahead h82sm13795626itb.38 - gsmtp

Subject: Message from ESP8266!
Mime-Version: 1.0
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: 7bit

opps the rest got truncated..

this forum doesn't like what I pasted. Anyway it sends exactly the same identical text. Could it be that the ESP32 does not code UTF-8 in 7 bits?


Hello RodrigoE32,

Did you had any look on improving the code for the ESP32?


The easiest way is to monitor pin state in loop function.

At the top of sketch after "#pragma region Globals" add:

const uint8_t triggerPin = 4; // I used pin 4 you can try different

then in setup function add:

pinMode(triggerPin, INPUT_PULLUP);

next modify loop function:

void loop(){
if(digitalRead(triggerPin)) // if pin HIGH
Gsender *gsender = Gsender::Instance();
if(gsender->Subject("PIN 4 HIGH")->Send("***yourMail***", "PIN 4 GOES HIGH")) {
Serial.println("Message send.");
} else {
Serial.print("Error sending message: ");

But be careful this code will constantly send emails while triggerPin is HIGH

you can use millis() function to count time from last email.

Hello, I have this working to send 1 email when input 4 is triggered. Would there be a way to send 1 email with pin 4 and send a different email with pin 0 ??


thank you soo much for your work! i have two more questions, though:

1. would it be possible to also implement the esp_deepsleep function for a more efficient notification system?

2.what would it take to convert all this awesome esp email craziness into a library so that the user only calls "ESPMAIL.begin(address,pwd,sendTO) or something like that in the beginning and espmail.send() lateron? this would be soo awesome since the code would then be wayy more understandable for noobs like me and i could (maybe?) implement all the functions i asked you for all by myself

Very cool Code!!!
I need a Code, for 2 or more Button.
Go a Button "High" sent a email.
Have Anywhere a code for me?
Or Snippets?

(Sorry for my bad English)

Brilliant! works great! Thanks so much for sharing. Opens up a whole new world of possibilities for the hobbyist.

Wonderful, Thanks to all of you....

Thanks! this works wonderfully! I am trying to modify this to email myself voltage levels from a battery that I am trying to monitor. What would be the best way to include a constantly changing voltage readout either in the subject or body? I currently have it configured to send me an email letting me know my voltage set point was broken, but I would like to include the actual voltage in a daily heartbeat email as well just to let me know its working.