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

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:

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.

Documentation:
https://www.arduino.cc/reference/en/libraries/emailsender/
We add the library to our project via 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++
Still worth completing the message:

We complete, upload and:

Success:

Email has been successfully sent.

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?
Comments