Send Email with Lua and the ESP32

 

Sending emails, especially those with attachments and inline images, can be a cumbersome task. However, the Xedge IDE simplifies this process through its user-friendly configuration dialog. This tutorial will guide you through setting up and using the Xedge SMTP configuration to enhance your email sending capabilities securely.

The Xedge IDE offers an easy-to-use configuration dialog for sending emails, including those with attachments and inline images. While you can send emails without this built-in feature, leveraging the Xedge SMTP configuration provides a significant advantage: it encrypts your email settings and credentials within the "xedge.conf" file for enhanced security when used on platforms such as Xedge32.
Before reading the remainder, be sure to subscribe and support the channel if you have not!
Subscribe:
Support:
Hire me at UpWork to build your IoT projects:

Step 1: Accessing the SMTP Configuration

  • Open the Xedge IDE.
  • Click the three dots in the upper right to reveal the menu.
  • Select "SMTP Server" to launch the configuration dialog.
    Here’s what the SMTP configuration dialog looks like:
    Xedge SMTP Configuration
    This dialog also activates the optional built-in email log function, xedge.elog(), which is useful for sending log messages, such as detailed stack traces and error messages, if your Lua scripts encounter issues.

    Step 2: Entering SMTP Settings

    After accessing the SMTP configuration dialog, enter your SMTP settings. Here's a breakdown of the settings for popular email providers:
    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 (details below)
      • SMTP Port: 465
      • Connection Security: TLS
        Generating an App Password for Gmail
        Gmail users need an App Password instead of their regular account password for SMTP settings. Follow these steps to generate an App Password:
        • Access your Google Account and navigate to the 'Security' section.
        • Under 'Signing in to Google, ' select '2-Step Verification' and proceed with the setup if not already activated.
        • Once 2-Step Verification is enabled, return to the 'Security' page and select 'App Passwords.'
        • In the 'Select app' dropdown, choose 'Mail.' For 'Select device, ' pick 'Other' and label it as 'Xedge.'
        • Click 'Generate' to receive a 16-digit App Password.
          Use this App Password as the authentication method for Xedge to send emails through your Gmail account.

          Step 3: Testing the Email Functions

          With your SMTP settings configured, test the email functions by sending a few emails. Follow these steps:
          • Click the three dots in the upper right to reveal the menu.
          • Select "Lua Shell" to launch the REPL.

            Example 1: Sending a Simple Text Message

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

            Conclusion

            Congratulations! You have successfully configured your SMTP settings and tested email functions using Xedge IDE. For more details on using the xedge.sendmail() function, refer to the Xedge Documentation.
            Additionally, if you need to log messages via email, check out the tutorial: Logging for Testing and Production Mode: Maximizing Efficiency with Xedge.
            For further assistance, explore our extensive collection of embedded web server and IoT tutorials tailored to guide you through each step. If you're pressed for time or need expert guidance, consider our consulting services to manage the complexities of networking, security, and device management.
            Happy emailing with Xedge!

            Create a free account to access full content.

            All access to code and resources on ShillehTek.

            Signup Now

            Already a member? Sign In

            Explore More on Our Blog

            How to Create a Time-Lapse Video with a Raspberry Pi Camera

            How to Create a Time-Lapse Video with a Raspberry Pi Camera

            Learn how to make a timelapse with your Raspberry Pi in Python.

            How to Integrate the MPU6050 with the STM32 Blue Pill

            How to Integrate the MPU6050 with the STM32 Blue Pill

            Learn how to measure acceleration with the STM32 and the MPU6050 in the Arduino IDE.

            Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

            Getting Started with STM32 Blue Pill in Arduino IDE Using a USB to TTL Converter — Write Your First Program

            This comprehensive tutorial will guide you through the process of setting up and programming the STM32 Blue Pill...

            Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

            Automate Task Scheduling in AWS with Lambda, Step Functions, and CloudWatch

            In this tutorial, I'll show you how to automatically schedule tasks in AWS at regular intervals using AWS...

            Implementing Google reCAPTCHA in a Simple React and Node.js App

            Implementing Google reCAPTCHA in a Simple React and Node.js App

            Learn how to protect your React applications from bots and spam with Google reCAPTCHA integration! This step-by-step tutorial...

            AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

            AWS Lambda Tutorial: Using Selenium with Chromedriver in Python

            In this tutorial, I will guide you through the process of running Selenium with ChromeDriver inside an AWS...

            How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

            How to Connect MLX90614 Infrared Thermometer to Raspberry Pi Pico W: MicroPython Tutorial!

            Learn how to use the MLX90614 with the Raspberry Pi Pico W and get infrared values in MicroPython.

            Raspberry Pi Pico/Pico W Free Simulator

            Raspberry Pi Pico/Pico W Free Simulator

            Discover how to simulate Raspberry Pi Pico projects using Wokwi, a free online simulator for Arduino and MicroPython....

            Interfacing the MPU6050 with Raspberry Pi Pico W in C++

            Interfacing the MPU6050 with Raspberry Pi Pico W in C++

            Interface with the MPU6050 using the Raspberry Pi Pico W in C++.

            How to Write your First C++ Program on the Raspberry Pi Pico W

            How to Write your First C++ Program on the Raspberry Pi Pico W

            Write your first C++ Program on the Pico W in a few simple steps.

            Back to blog

            Leave a comment

            Please note, comments need to be approved before they are published.