ESP8266 GMail Sender

146,680

658

179

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

2019 Update:

  • This code doesn't work with ESP8266 core for Arduino version 2.5.0!
  • Temporary solution use core version 2.4.2


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 (ESP8266_Gmail_Sender.zip).

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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 ESP8266_Gmail_Sender.zip
  • 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("boris.on@live.com", "Setup test"))

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

Change recipient from boris.on@live.com 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 base64encode.org for encoding, result must be something like:

const char* EMAILBASE64_LOGIN = "Y29zbWkxMTExMUBnbWFpbC5jb20=";
const char* EMAILBASE64_PASSWORD = "TGFzZGFzZDEyMzI=";
  • Now set FROM field.
const char* FROM = "your_email@gmail.com";

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!

Recommendations

  • Assistive Tech Contest

    Assistive Tech Contest
  • Reuse Contest

    Reuse Contest
  • Made with Math Contest

    Made with Math Contest

179 Discussions

0
None
PhuriphakP

4 weeks ago

Worked Well!!! Thank you, If i need to sent multi email address is possible?

1 reply
0
None
PhuriphakPPhuriphakP

Reply 4 weeks ago

I found your reply in other comment and Now I worked Great !! Thank you bro.

0
None
casaanaalmeida

6 weeks ago

It worked TOP, thank you.
Guys DONT forget to Allow less secure apps on google account!!

0
None
Del2147

2 months ago

Worked well! Thank you for the tutorial :^)

0
None
ElbertL

4 months ago

Thanks a bunch, took a little while to get it working since I am new at the Arduino and ESP Node MCU. I will use the this gmail feature to notify me on any cretical issues with my backyard Aquaponics. Thanks again for the great work.

1 reply
0
None
yashupadhyay32ElbertL

Reply 3 months ago

Is it working ? Even I am also new to this & I have nodemcu ! Will it work with this ? Any suggestion will be helpful.

0
None
yagan98

3 months ago on Introduction

Thank you very very much, email sent OK. People don't forget to use ESP8266 Arduino core 2.4.2 the new one doesn't work

0
None
murali123muluka

Question 4 months ago

hi,
am getting this error while running my program as
"Sending To
550 that smtp username's account is not allowed to send"
but am not able to get he solution from smtp server. please help me any one.
thank you.

0
None
murali123muluka

Question 4 months ago

hi, nice project.
i have tried this one with nodemcu esp8266 with the help of your file, and i had done changes according to the program, am getting the problem as couldn't connect to server. can some one give me replay?. thank you.

0
None
FrankForsberg

Question 4 months ago

Great Library! Thanks!
I just wonder if there is some way to add an attachment into the mail?

0
None
Olgorofi

Question 4 months ago on Step 3

Dear friend.
I used an ESP8266 and did according to its instructions: I unpacked the program, changed according to my email information, I changed the Gsender.h as 64bit encoding, I recorded it. I executed and continue giving error of message sending. The email placed in Gsender.h is what it will send to the other sletch email. Do you agree? Email address is XXX@gmail.com XXX, do you agree? Thank you

0
None
mabazug

Question 1 year ago

Hello

Great Job !!!

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

Regards

Mabazug

2 answers
2
None
Higanymabazug

Answer 1 year 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("xy@gmail.com", "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("xy@gmail.com", (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: <xy@gmail.com>
Body of message Say something about your variable: 3.65 Unit
(variable value was 3.65)


0
None
OttoNLhenkoegema

Reply 10 months 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.

0
None
dheerajgurjar

8 months ago

while running ESP8266 Gmail Sender We are getting
error: Mail server could not connect
Can someone help me??
Thanks in advance

1 reply