Skip to content

ESP32 Xedge SMTP: Send Email Securely | ShillehTek

May 15, 2024

Video Tutorial (Optional)

Watch first if you want to follow along as the SMTP settings are configured and a test email is sent from the Lua shell.

Project Overview

In this tutorial, you use an ESP32 running Xedge (Xedge32) to configure the Xedge SMTP settings and send email from Lua using xedge.sendmail().

Sending emails (including attachments and inline images) can be cumbersome, but the Xedge IDE provides a configuration dialog that also encrypts your email settings and credentials in xedge.conf for improved security on platforms such as Xedge32.

  • Time: 15 to 30 minutes
  • Skill level: Beginner
  • What you will build: An SMTP configuration in Xedge plus a Lua test script that sends an email

If you want to support the original creator resources used in this post:

Parts List

From ShillehTek

  • None required for this software configuration tutorial

External

  • ESP32 running Xedge (for example, Xedge32)
  • Xedge IDE
  • An email account with SMTP access (Outlook/Hotmail or Gmail)

Note: Gmail requires an App Password for SMTP (not your normal account password). Outlook/Hotmail commonly uses STARTTLS on port 587.

Step-by-Step Guide

Step 1 - Open the SMTP configuration dialog

Goal: Access Xedge IDE's built-in SMTP configuration UI.

What to do: Open the Xedge IDE, click the three dots in the upper right to reveal the menu, then select SMTP Server to launch the configuration dialog.

This dialog also activates the optional built-in email log function, xedge.elog(), which can be used to send log messages such as detailed stack traces and error output from Lua scripts.

Expected result: The SMTP configuration dialog is visible and ready for you to enter provider settings.

Step 2 - Enter your SMTP provider settings

Goal: Configure SMTP host, authentication, port, and encryption so Xedge can send email securely.

What to do: In the SMTP configuration dialog, enter the settings that match your email provider.

SMTP Settings for Hotmail and Outlook:

  • SMTP Server: smtp.office365.com
  • SMTP Username: Your complete Outlook email address
  • SMTP Password: Your Outlook account password
  • SMTP Port: 587
  • Connection Security: STARTTLS

SMTP Settings for Gmail:

  • SMTP Server: smtp.gmail.com
  • SMTP Username: Your full Gmail address
  • SMTP Password: Your Gmail App Password (see next step)
  • SMTP Port: 465
  • Connection Security: TLS

Expected result: Your SMTP settings are saved via the Xedge IDE and stored securely (encrypted) in xedge.conf on supported platforms such as Xedge32.

Step 3 - Generate a Gmail App Password (Gmail only)

Goal: Create the correct SMTP credential for Gmail.

What to do: If you are using Gmail, generate an App Password and use it as the SMTP password in Xedge:

  • Access your Google Account and navigate to the Security section.
  • Under Signing in to Google, select 2-Step Verification and complete setup if it is not already enabled.
  • Return to the Security page and select App Passwords.
  • In Select app, choose Mail. In Select device, choose Other and label it as Xedge.
  • Click Generate and copy the 16-digit App Password.

Use this App Password as the authentication method for Xedge to send emails through your Gmail account.

Expected result: You have a Gmail App Password ready to paste into the Xedge SMTP configuration.

Step 4 - Test email sending from the Lua shell

Goal: Confirm SMTP is working by sending a test email using xedge.sendmail().

What to do: Click the three dots in the upper right to reveal the menu, then select Lua Shell to launch the REPL. Run the example below.

Code:

local op={
   to="info@realtimelogic.com",
   subject="Hello",
   body="What's up?"
}
xedge.sendmail(op, function(ok,err) trace(ok,err) end)

Expected result: The callback prints a success value (or an error message you can use to correct the SMTP settings).

Conclusion

You configured SMTP in the Xedge IDE for an ESP32 (Xedge32) setup and tested sending a message from Lua using xedge.sendmail(). The Xedge SMTP dialog also enables xedge.elog() for emailing logs when your Lua scripts need remote visibility.

For more details on using xedge.sendmail(), refer to the Xedge Documentation. If you need to log messages via email, see: Logging for Testing and Production Mode: Maximizing Efficiency with Xedge.

Want the exact parts used in your next ESP32 build? Grab them from ShillehTek.com. If you want help customizing this project or building something for your product, check out our consulting: https://shillehtek.com/pages/iot-consulting.