Send Email with ESP8266 and Arduino

Send Email with ESP8266 and Arduino © CC BY-NC-SA

A simple method to notify a problem is to use email, It’s very usefully and simple to share, so I created a library to do it.

  • 1,495 views
  • 0 comments
  • 8 respects

Components and supplies

Apps and online services

About this project

A simple method to notificate a problem is to use email, It’s very usefully and simple to share, so I created a library to do It. I get some code from GSender a library that It’s quite simple, but not so complete and configurable.

Esp8266 and Arduino EMailSender library

This library use the SMTP:

The Simple Mail Transfer Protocol (SMTP) is a communication protocol for electronic mail transmission. As an Internet standard, SMTP was first defined in 1982 by RFC 821, and updated in 2008 by RFC 5321 to Extended SMTP additions, which is the protocol variety in widespread use today. Mail servers and other message transfer agents use SMTP to send and receive mail messages. Proprietary systems such as Microsoft Exchange and IBM Notes and webmail systems such as Outlook.com,  Gmail and Yahoo! Mail may use non-standard protocols internally, but all use SMTP when sending to or receiving email from outside their own systems. SMTP servers commonly use the Transmission Control Protocol on port number 25. (cit WiKi)

For the examples I use a gmail dedicated account, I create a new one account because you must reduce security to use It with an external program.

Library

You can find my library here.

To download.

Click the DOWNLOADS button in the top right corner, rename the uncompressed folder EMailSender.

Check that the EMailSender folder contains EMailSender.cpp and EMailSender.h.

Place the EMailSender library folder your /libraries/ folder.

You may need to create the libraries subfolder if its your first library.

Restart the IDE.

Usage

Constructor: Default value is quite simple and use GMail as smtp server.

EMailSender emailSend("smtp.account@gmail.com", "password");

If you want use onother provider you can use more complex (but simple) contructor

EMailSender(const char* email_login, const char* email_password, const char* email_from, const char* smtp_server, uint16_t smtp_port);

You must connect to WIFI :P.

Create a message with the structure EMailMessage

EMailSender::EMailMessage message;
message.subject = "Subject";
message.message = "Hi, How are you<br>Fine.";

Send message:

EMailSender::Response resp = emailSend.send("account_to_send@gmail.com", message);

Then check the response:

Serial.println("Sending status: ");
Serial.println(resp.code);
Serial.println(resp.desc);
Serial.println(resp.status);

Example output:

Connection: ESTABLISHED
Got IP address: 192.168.1.104
Sending status:
1
0
Message sent!

GMail enable

Allow less secure apps to access your Gmail account

Google may block sign-in attempts from some apps or devices that do not use modern security standards. Since these apps and devices are easier to break into, blocking them helps keep your account safe.

To disable this security feature:

This setting may not be available for:

For G-Suite users: Enabling less secure apps to access accounts

Sign in to your Google Admin console (Sign in using an administrator account, not your current account.

  • Click Security > Basic settings.
  • Under Less secure apps, select Go to settings for less secure apps.
  • In the subwindow, select the Allow users to manage their access to less secure apps radio button.

Once you’ve set Allow usersto manage their access to less secure apps to on, affected users within the selected group or Organizational Unit will be able to toggle access for less secure apps on or off themselves.

G-Suite admins: Enforcing access to less secure apps for all users

Use this setting when you want to ensure that access by a less secure app is available to all for a limited time, such as for upgrades.

Sign in to your Google Admin console.Sign in using an administrator account

  • Click Security > Basic settings.
  • Under Less secure apps, select Go to settings for less secure apps.
  • In the subwindow, select the Enforce access to less secure apps for all users radio button.

Once you’ve set Enforce access to less secure apps for all users to on, affected users within the selected group or Organizational Unit will not be able to toggle access for less secure apps off themselves. You will have to set the setting back to Allow users to manage their access to less secure apps to allow them to toggle access for less secure apps on or off themselves.

Thanks

GitHub library

Update and related articles

Code

Code snippet #5Plain text
    Serial.println("Sending status: ");
    Serial.println(resp.code);
    Serial.println(resp.desc);
    Serial.println(resp.status);
Code snippet #6Plain text
Connection: ESTABLISHED
Got IP address: 192.168.1.104
Sending status: 
1
0
Message sent!
Github
https://github.com/xreef/EMailSender

Comments

Similar projects you might like

Send SMTP email with Arduino and ESP8266

by Team Hans

  • 7,987 views
  • 9 comments
  • 11 respects

Telegram Bot with ESP8266

Project tutorial by Shebin Jose Jacob

  • 33,143 views
  • 42 comments
  • 69 respects

Send An Email From Your Gmail Account With Temboo

Project tutorial by Temboo_OFFICIAL

  • 1,557 views
  • 0 comments
  • 2 respects

ESP8266 - Beginner Tutorial + Project

by Inventor Niv

  • 20,476 views
  • 6 comments
  • 47 respects
Add projectSign up / Login