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 2874 0

TL;DR

  • An ESP8266/NodeMCU sends notifications by email instead of SMS using SMTP and the PlatformIO-based EMailSender library.
  • Setup uses mailbox SMTP settings, WiFi credentials, and a target address, with fields marked "YOUR_" in the example code.
  • OneT settings shown are smtp.poczta.onet.pl, SSL, and port 465.
  • After completing the code and uploading it, the ESP successfully sends the email.
  • A working WiFi connection is required before testing the example.
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
📢 Listen (AI):
  • 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?

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 14439 posts with rating 12405, helped 650 times. Been with us since 2014 year.
  • ADVERTISEMENT
📢 Listen (AI):

FAQ

TL;DR: With 1 library and SSL port 465, you can send free ESP8266 email alerts; as the author says, "Email has been successfully sent." This FAQ is for ESP8266 or NodeMCU users who want simple SMTP notifications in PlatformIO instead of paid SMS alerts. [#21192134]

Why it matters: It gives ESP-based projects a low-cost way to send alarms, status messages, and automation alerts over standard email.

Method Cost in the thread Setup complexity Example use
SMTP email Free Simpler Temperature alert
SMS Not free More complex Phone notification

Key insight: The fastest path is to reuse the EMailSender example, then replace every YOUR_... placeholder with your WiFi, SMTP, and mailbox details. One correct SMTP host, one SSL port, and valid login data are enough for a basic alert sender. [#21192134]

Quick Facts

  • The thread uses SMTP over SSL with port 465 for an Onet mailbox, and the SMTP host shown is smtp.poczta.onet.pl. [#21192134]
  • The WiFi connect loop waits up to 50 iterations with 200 ms delays, so one attempt lasts about 10 seconds before timeout. [#21192134]
  • The sketch sets reconnect_interval to 10000 ms and starts Serial at 9600 baud before sending mail. [#21192134]
  • The example alert uses subject "Notification ESP Elektroda" and message "Temperature is too high (123)", showing how to send simple sensor alarms. [#21192134]

How do I send an email from an ESP8266 over SMTP using PlatformIO and the EMailSender library?

Use PlatformIO, add the EMailSender library, fill in your WiFi and mailbox data, then run the example sketch.
  1. Add EMailSender to the PlatformIO project.
  2. Replace YOUR_... fields with SSID, WiFi password, email, SMTP host, port, and target email.
  3. Build, upload, and call emailSend.send(...) with a subject and message body.
The thread shows this working on a NodeMCU with SSL SMTP and a successful send result. [#21192134]

What is SMTP, and how does it differ from POP3 and IMAP in an ESP8266 email project?

SMTP is the protocol used here to send email from the ESP8266. "SMTP" is a text protocol that sends email, using simple commands between a client and a mail server. The thread names POP3 and IMAP as other mail protocols, but it uses SMTP because sending notifications is the goal. For this project, SMTP is the relevant choice, while POP3 and IMAP are only mentioned as alternatives in the mail ecosystem. [#21192134]

Where can I find the SMTP server address, security type, and port for an Onet mailbox before configuring an ESP8266?

Find them in your mailbox settings, where SMTP may also need to be enabled first. The thread shows these exact Onet values: SMTP server smtp.poczta.onet.pl, security type SSL, and port 465 or the default SSL port. You also need the mailbox email address and password before filling the ESP8266 sketch. [#21192134]

What is SMTP-AUTH, and when does it matter while sending mail from a NodeMCU or ESP8266?

SMTP-AUTH matters when the mail server requires login credentials before it accepts outgoing mail. "SMTP-AUTH" is a mail authentication method that verifies the sender with account credentials, adding access control before message delivery. In the thread, authentication matters because the constructor includes your email address and email password, and the mailbox must allow SMTP sending. [#21192134]

Which fields in the EMailSender example code need to be replaced with my own WiFi, SMTP, and email account details?

Replace every placeholder that starts with YOUR_. The thread explicitly says to fill in YOUR_SSID, YOUR_WIFI_PASS, YOUR_EMAIL, YOUR_EMAIL_PASS, YOUR_SMTP_ADR, YOUR_SMTP_PORT, and YOUR_TARGET_EMAIL. You should also edit the message subject and body so the alert matches your project. [#21192134]

Why does my ESP8266 SMTP sketch get stuck while connecting to WiFi, and how should I troubleshoot the timeout messages?

It usually times out because the ESP8266 never reaches WL_CONNECTED within about 10 seconds. The loop checks WiFi status up to 50 times, waits 200 ms each time, and then prints Connection: TIMEOUT. The sketch itself suggests checking whether the access point is available and whether the SSID and password are correct. If the first attempt fails, Awaits() retries every 10000 ms. [#21192134]

How do I set the correct SSL port, such as 465, in the EMailSender constructor for an ESP8266 project?

Pass the SMTP port as the last constructor argument. The thread shows EMailSender emailSend(..., "YOUR_SMTP_ADR", YOUR_SMTP_PORT); and states that an Onet mailbox uses SSL with port 465. In practice, you replace YOUR_SMTP_PORT with 465 and keep the SMTP host consistent with the same mailbox settings. [#21192134]

What does the EMailSender response status, code, and description mean after trying to send an email?

They report whether the send attempt succeeded and how the library describes the result. After emailSend.send(...), the example prints resp.status, resp.code, and resp.desc to Serial. The thread uses those three fields as the basic post-send check, then shows a successful outcome with the message arriving in the mailbox. [#21192134]

SMTP email vs SMS notifications on an ESP-based device — which approach is better for free alerts and simple automation?

SMTP email is the better fit in this thread because it is free and simpler to set up. The author explicitly says email is completely free and often much simpler than sending an SMS. If your project only needs alerts like warnings or status notifications, the shown SMTP method gives a lower-cost starting point than SMS. [#21192134]

How can I customize the subject and message body in the ESP8266 email example to send alerts like high temperature warnings?

Edit the EMailMessage fields before calling send(). The thread shows message.subject = "Notification ESP Elektroda"; and message.message = "Temperature is too high (123)";. You can replace both strings with your own alert text, so a sensor event, alarm condition, or automation status becomes the email content. [#21192134]

What is PlatformIO, and why is it useful for building an ESP8266 or Wemos D1 email notification project?

PlatformIO is the build environment used in the thread to create, manage, and upload the ESP8266 project. It is useful here because you can add the EMailSender library directly to the project, then compile and run the example without building the SMTP logic yourself. The author also links PlatformIO-based tutorials for Wemos D1 and ESP12 as the setup base. [#21192134]

How do I prepare a basic ESP8266 project with working WiFi or a Blink test before adding SMTP email sending?

Start with a project that already proves the board and toolchain work. The thread says you should have either a working WiFi connection or at least a classic Blink led project as a base before adding SMTP. That baseline helps isolate problems, because you can confirm upload, board selection, and basic runtime behavior before introducing email code. [#21192134]

What common mistakes in SSID, WiFi password, SMTP address, email login, or target address can prevent an ESP8266 from sending mail?

Wrong credentials or server values are the main failure points shown in the thread. A bad SSID or WiFi password causes connection timeout, while a wrong SMTP host, wrong port, wrong email password, or wrong target address can stop delivery after WiFi connects. The example requires all placeholders to be replaced, so leaving any YOUR_... value unchanged is an obvious error case. [#21192134]

How well does the Renzo Mischianti EMailSender library work across Arduino, ESP8266, and ESP32 platforms for SMTP mail sending?

The thread presents it as a cross-platform SMTP library, not an ESP8266-only tool. It states that the EMailSender library by Renzo Mischianti lets you send email on multiple platforms, and the included code comment names Arduino, ESP8266, and ESP32 support. That makes it a practical option if you want similar mail logic across several boards. [#21192134]

What practical uses are there for SMTP email notifications in ESP-based projects, such as alarms, monitoring, or automation alerts?

Use SMTP email when your ESP project needs simple, free notifications. The thread demonstrates a temperature alarm with the text Temperature is too high (123), which fits monitoring and warning tasks. The same pattern also suits status emails, automation events, and user notifications sent directly from a NodeMCU or similar ESP-based device. [#21192134]
Generated by the language model.
ADVERTISEMENT