logo elektroda
logo elektroda
X
logo elektroda

How to send an email with ESP8266 via SMTP? Almost like an SMS but for free

p.kaczmarek2 
Email notification with the subject Notification ESP Elektroda and a message about high temperature. .
How do we send a notification to a user from our ESP-based device? One way might be to use email. This is completely free and often much simpler than, for example, sending an SMS message. Here I will show how to easily send a message based on the SMTP service. I will use a ready-made library from PlatformIO for this and it will be even better than I announced, because it is quite cross-platform. Here we go!

What is SMTP?
SMTP, or "Simple Mail Transfer Protocol", is a simple text protocol that allows you to send email. SMTP is described by RFC 821 and RFC 5321 . SMTP is not the only "mail" protocol, because we still have POP3, IMAP or there SMTP-AUTH, but for our applications the simplest one will suffice....

We will now try to run SMTP on the NodeMCU in a few simple steps.

1. Find your SMTP data .
Depending on the mailbox you have, this process may vary slightly. At my OneT, they are in the settings. There you also have to enable SMTP first:
Screenshot of Onet mail settings with SMTP option highlighted. .
Save:

Serwer SMTP: smtp.poczta.onet.pl
Typ zabezpieczeń: SSL
Port: domyślny lub 465
.
We will still need our email and password.

2. Run PlatformIO for your board .
PlatformIO has already been discussed:
How to program a Wemos D1 (ESP8266) board in the shape of an Arduino? ArduinoOTA in PlatformIO .
Clock on ESP12 and MAX7219 display - tutorial - part 1, ArduinoOTA, basics
We need to have a working WiFi connection or at least a classic "Blink led" as a base.

3. Download the EmailSender library .
The EMailSender library by Renzo Mischianti allows you to conveniently send emails via SMTP on multiple platforms.
Screenshot from PlatformIO showing search results for the EMailSender library. .
Documentation:
https://www.arduino.cc/reference/en/libraries/emailsender/
We add the library to our project via PlatformIO:
Adding project dependency in PlatformIO. .
Once added, all you need to do is run the example code, I've included an example from the library author below (I've only added the port space).

4. Run the example code .
Complete the data in the code:
- SMTP server
- our email and its password
- our SSID and WiFi password
- target email
The data to be completed starts with "YOUR_" in this code.
Code: C / C++
Log in, to see the code
.
Still worth completing the message:
A portion of C++ source code for a program on ESP8266 sending emails. .
We complete, upload and:
Console showing the process of connecting to WiFi and sending an email. .
Success:
Inbox view with an email notification from a test application. .
Email has been successfully sent.
Email notification with the subject Notification ESP Elektroda and a message about high temperature. .

Summary
Sending emails from our ESP-based project turned out to be very easy indeed - we have a ready-made library for everything, as well as the SMTP service being free. Now we can only wonder what we might use it for - do you have any ideas? Do you use SMTP in your projects?

About Author
p.kaczmarek2
p.kaczmarek2 wrote 11968 posts with rating 9997 , helped 572 times. Been with us since 2014 year.

Comments

%}