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.

2018 Update:

Here is newer code written as arduino lib. It supports multiple recipients.
Also no need to encode login and password to base64 now it uses ESP core base64 lib. github

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!


  • PCB Contest

    PCB Contest
  • Warm and Fuzzy Contest

    Warm and Fuzzy Contest
  • Faux-Real Contest

    Faux-Real Contest

154 Discussions


2 months ago

How can I send e-mail wtith MycroPython on ESP8266 ?

1 reply

Reply 6 days ago

I tried to use MicroPython to send e-mail but I quickly gave up.
You will need a library that allows you to send e-mail in Python.
With Arduino you can just install libraries. With normal desktop Python you can do that too. But with MicroPython you only have the select libraries that come with it, I think you can make a custom MicroPython build with extra libraries and flash that to the ESP8266, but I couldn't find out how. There's a MicroPython forum where you could ask.

I decided to just learn to work with the Arduino IDE (using C++) as there are many thousands of Arduino tutorials out there that work on ESP's and there aren't a lot of MicroPython tutorials out there.
It also makes it much easier to communicate with sensors. And it's faster then MicroPython. There's definitely a place for MicroPython, but I flashed MicroPython to my ESP because I thought it would be easier then using C++ as I already know Python a bit, but actually learning C++ made everything much, much easier for me.


27 days ago

Hello, I've been tried to use this code and i had some difficults. i have this:
Got IP address:
Error sending message: Could not connect to mail server

Anyone knows how can i solve this?

Thank you!

2 replies

Reply 15 days ago

Your problem is probably the ESP8266 core version you are using. The new 2.5.0_betaX is using BearSSL. If you downgrade to anything lower than beta1 you will have AxTLS and should be good to go. Worked for me.
It also works with 2.5.0-beta2 core if you switch to WiFiClientSecureAxTLS.h as this uses the old AxTLS.


27 days ago on Step 2

Please change your password on your email.
With reverse engineering on b64 is posible to get your password of email.


4 weeks ago on Step 3

Hi, is it possible to send anexo file.txt in Attachment using your example ?


5 weeks ago

Well, well, well. That went well; Thanks.
It took a while as I did not understand it all in one go, lack of experience I have never used the "include" a separate file before, but with some careful thought and the best part of a day I got there.
I had already tried other folks offering and after a lot longer came upon yours, THANK YOU.
You have helped me a lot, I will be looking at the code in more depth and I will learn, I am sure, quite a bit more. Onward and Upward.

2 replies
Rudy TrujilloDiez66

Reply 5 weeks ago

Would you either look at my files or post yours cause I can' get this working

Diez66Rudy Trujillo

Reply 4 weeks ago

Sorry, cannot look at yours, I have spend a Long Time on this project and am now at the Family Holidays time and then I must build the physical project and test prior to deployment.

I did not actually build this exact project, what I did was use the "How to use IFTTT" with the Arduino 8266 and build a low tempo sensing switch with web server and email status reporting. It has taken about 3 weeks to get the software running.

What I have done is include the listing of the "Bare Bones" send a Webhook request and that resulted in an Gmail message back from IFTTT.
I basically removed all the other stuff I could, while keeping it able to compile, and then used this code as the function in my, otherwise failing, project.

I hope it helps.
#include <ESP8266WiFi.h>
#include <arduino.h>
#include "DataToMaker.h"
// Define program constants
String Value1 = "Burger";
String Value2 = "King";
String Value3 = "Whooper";
// json values are = "?value1=Burger&value2=King&value3=Whopper"
const char* myKey = "ThisIsYourWebHooksKeya$"; // your maker key here
const char* ssid = "YourSSID"; // your router ssid here
const char* password = "YourWiFiPassword"; // your router password here
// declare new maker event with the name "ESP"
DataToMaker event(myKey, "WebHookName_1");// was ESP
bool connectedToWiFI = false;
void setup()
Serial.println("Start setup");
delay(10); // short delay
void loop() {
if (wifiConnected)
if (Dummy())
Serial.println("Connected To Maker");
// set json values and send
if (event.connect())
delay(1000); // short delay
else Serial.println("Failed To Connect To Maker!");
delay(1000); // pause for 1 second
delay(6 * 1000); // 1 minute delay before trying to re connect
bool ConnectWifi()
// Connect to WiFi network
Serial.print("Connecting to ");
unsigned long startTime = millis();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED && startTime + 30 * 1000 >= millis()) {
if (WiFi.status() == WL_CONNECTED)
Serial.println("WiFi connected");
Serial.println("WiFi Timed Out!");
bool wifiConnected()
return WiFi.status() == WL_CONNECTED;
bool Dummy()



Question 4 weeks ago on Introduction

Please how do I modify the code to send temperature reading to Gmail whenever a Mac/minimum level is reached?

Rudy Trujillo

5 weeks ago

I have been at this a couple of days. So far all I get is: auth failure or cannot connect and this is using Hotmail and Gmail. Used the files called out in this tutorial but no success. I can post my files on Pastebin if anyone can help or if those having success could post theirs it would be great. (and Link here).

Daniel Morales

2 months ago

i need help, with a project I wanna make... using this, I want to have an email sent, "to my phones SMS gateway, wich I already have" when someone presses my doorbell "433 mhz" I have all the parts, have sniffed out the doorbell code, I want to recieve a message once the doorbell is pressed... It is possible, just not too sure about the coding!


Question 3 months ago


Great Job !!!

One Question: Is it posible to send variables ? eg Temp etc ?



1 answer

Answer 2 months ago

Try replace these lines in the example:

Gsender *gsender = Gsender::Instance(); // Getting pointer to class instance
String subject = "Subject is optional!";
if(gsender->Subject(subject)->Send("", "Setup test")) {

with this:

Gsender *gsender = Gsender::Instance(); // Getting pointer to class instance

String subject = "Subject text"; // text
subject += " Say something about your variable: "; // text
subject += String(variable); // the variable you want to send
subject += " Unit "; // text
String message = "Body of message"; // text
message += " Say something about your variable: "; // text
message += String(variable); // the variable you want to send
message += " Unit "; // text
if (gsender->Subject(subject)->Send("", (message))) { // replace the e-mail address

You will receive an e-mail like this:
Subject: Subject text Say something about your variable: 3.65 Unit
To: <>
Body of message Say something about your variable: 3.65 Unit
(variable value was 3.65)


3 months ago

Hallo Borya,
have you a similar library and example to read with IMAP an email.
Your project to send emails ist SUPER.


Tip 3 months ago

Here is newer code written as arduino lib. It supports multiple recipients.

Also no need to encode login and password to base64 now it uses ESP core base64 lib.


Question 6 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?

2 answers