ESP8266 GMail Sender




Intro: 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...

13 People Made This Project!


  • Metalworking Contest

    Metalworking Contest
  • Audio Contest 2018

    Audio Contest 2018
  • Furniture Contest 2018

    Furniture Contest 2018

135 Discussions


39 minutes ago

Your script works great but I have a question. Every email ESP8266 script I have come across only allows one email to be sent. Can you suggest how to modify your program to send an email after each press of a switch connected to the ESP8266 that does not include having to use some type of IoT or IoE? I was able to do it with an Arduino UNO with an ethernet shield. Is this something an ESP8266 just can't do?


12 days ago

Great post!

Edited the Gsender.h file on hard drive initially and had problems, but then saw tab in IDE, edited there and it works great. Used python for base64, code/example for any python fans:

import base64
>>> base64.b64encode('')


17 days ago

Been struggling for hours here - all connects perfectly to GMail but never gets a 250 after sending message body. Finally found post suggesting putting whole body text in one string including <CR LF>. <CR LF> eom signature. This worked :-)


client.println("\r\n <!DOCTYPE html><html lang=\"en\">" + message + "</html> \r\n.\r\n");

Thanks for your instructable.


Question 3 months ago

How would I send to multiple recipients so the recipiants could view who else was emailed in the "To:" header of the received email?


1 year ago

I have done everything described on your tutorial, and I always have the error about missing the wifi settings. Actually my question is where I have to get ESP8266WiFi.h cause I think that I don't have it.

I'm a beginner and I have to make the progect with trash box that send email when it's full. i'm using a different model of esp 8266. It's simplier than yours

Heeeeeelp me please!!!!

1 reply

Reply 3 months ago

I know its been 11 months since you asked so I hope you got it to work, but I will address it anyway.
The ESP8266WiFi is part of your ESP8266 core that you should have installed.
the amazon link shows an esp8266-01, whereas this project is done with an ESP8266-12, that breaks out more pins, but in essence there is not so much difference

Simone Florit

Question 3 months ago

Hi boris , this is my problem's text: #include "Gsender.h" .

I can't fix the problem

1 more answer
diy_blokeSimone Florit

Answer 3 months ago

Your question is easier to answer if you say what your problem with #include "Gsender.h" is.
Anyway, I am going to throw in a few possibilities
1: you have not installed the Gsender.h lib ->install it
2: you have put it in the wrong place. with #include "Gsender.h", the compiler expects to find it in the sketch directory. If you are using the greater than and smaller than signs it expects to find it in the libraries folder


Usted podría enviarme el código completo utilizado para el Wemos D1. Soy novato en este ambiente. Gracias por su atención. Luiz


4 months ago

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


4 months ago

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.


Question 7 months ago

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.

1 more answer

Answer 5 months ago

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


6 months ago on Step 3

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


8 months ago

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

4 replies

Reply 8 months ago

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


Reply 7 months ago

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