Error: 'SMTP_Config' does not name a type; did you mean 'IMAP_Config'?

Hello,

I am the nuube everyone talks about.

I used Copilot to successfully set up an ESP-Wroom-32 board using Arduino IDE 2.3.2 to read a temperature sensor in a remote freezer and send the data to a webpage. That was 'relatively' easy once I understood adding libraries better.

Now want to have the code send me an email, or preferably a SMS text, if the temperature exceeds a defined value. Copilot generates the code but the new stuff does not compile.

Here's the code:

#include "WiFi.h"
#include "WebServer.h"
#include <ESP_Mail_Client.h>
#include "SD.h"

// Replace with your network credentials
const char* ssid = "SSSSSSSSSS-2g";
const char* password = "PPPPPPPP";

// Create an instance of the server
WebServer server(80);

// Define the threshold value
const float threshold = 20.0; // Example threshold temperature value

// Email credentials
const char* smtp_server = "smtp.gmail.com";
const int smtp_server_port = 465; // Use 465 for SSL
const char* email_sender = "XXXXXXXX@gmail.com";
const char* email_password = "PPPPPPPP"; // Use app password if 2FA is enabled
const char* email_recipient = "ME@gmail.com";

// Initialize the SMTP session
SMTPSession smtp;

// Declare the session config data
SMTP_Config config;

void configSMTP() {
  // Set the SMTP server and port
  config.smtp.host_name = smtp_server;
  config.smtp.port = smtp_server_port;
  config.login.email = email_sender;
  config.login.password = email_password;
  // For SSL/TLS connection
  config.smtp.starttls = true;
  // Set the debug level
  config.debug_level = 1;
  
  // Set the configuration to the SMTP session
  smtp.setConfig(&config);
}

// Function to send an email
void sendEmail(float sensorValue) {
  SMTP_Message message;

  // Set the subject, sender, and recipient
  message.subject = "Freezer Temperature Alert";
  message.sender.name = "Jay"; // Replace with your name
  message.sender.email = email_sender;
  message.addRecipient("Jay", email_recipient); // Replace "Recipient Name" with the actual name

  // Set the email message
  String textMsg = "The sensor value is " + String(sensorValue) + " which exceeds the threshold.";
  message.text.content = textMsg;
  message.text.charSet = "us-ascii";
  message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;

  // Send the email
  if (!MailClient.sendMail(&smtp, &message)) {
    Serial.println("Error sending Email, " + smtp.errorReason());
  }
}

// Handler for the root path
void handleRoot() {
  float sensorValue = readSensor(); // Read the sensor value
  
  if (sensorValue > threshold) {
    sendEmail(sensorValue); // Send an email if the sensor value exceeds the threshold
  }
  
  String html = "<html><head><title>ESP Sensor Data</title></head><body>";
  html += "<h1>Sensor Data</h1>";
  html += "<table border=\"1\"><tr><th>Measurement</th><th>Value</th></tr>";
  html += "<tr><td>Temperature</td><td>" + String(sensorValue) + " °C</td></tr>";
  html += "</table></body></html>";
  
  server.send(200, "text/html", html);
}

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting to WiFi...");
  }
  
  Serial.println("Connected to the WiFi network");
  Serial.println(WiFi.localIP());
  
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
  
  // Configure the SMTP session
  configSMTP();
}

void loop() {
  server.handleClient();
}

// Dummy function to simulate reading sensor data
float readSensor() {
  // Replace with actual sensor reading code
  return 23.5; // Example temperature value
}

Here are the error messages.

U:\Adventor\Public_Market_Freezer_Monitoring\Public_Market_Freezer_Monitoring.ino:26:1: error: 'SMTP_Config' does not name a type; did you mean 'IMAP_Config'?
   26 | // Declare the session config data
      | ^~~~~~~~~~~
      | IMAP_Config
U:\Adventor\Public_Market_Freezer_Monitoring\Public_Market_Freezer_Monitoring.ino: In function 'void configSMTP()':
U:\Adventor\Public_Market_Freezer_Monitoring\Public_Market_Freezer_Monitoring.ino:30:3: error: 'config' was not declared in this scope
   30 |   // Set the SMTP server and port
      |   ^~~~~~
U:\Adventor\Public_Market_Freezer_Monitoring\Public_Market_Freezer_Monitoring.ino:40:8: error: 'class SMTPSession' has no member named 'setConfig'
   40 |   // Set the configuration to the SMTP session
      |        ^~~~~~~~~
Multiple libraries were found for "SD.h"
  Used: C:\Users\Maker\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.1\libraries\SD
  Not used: C:\Users\Maker\AppData\Local\Arduino15\libraries\SD
  Not used: C:\Users\Maker\Documents\Arduino\libraries\SD
exit status 1

Compilation error: 'SMTP_Config' does not name a type; did you mean 'IMAP_Config'?

The error about the multiple SD.h libraries resolves itself and successfully compiles so can be ignored.

I've tried to research the other errors and suspect it has something to do with something inside one of the libraries but haven't been able to resolve the issues.

Hope I posted this properly.

Any help would be appreciated.

Jay

Which version of the ESP32 board package do you use? If it's version 3.x, see if rolling back to the latest 2.x version of the board package will solve the issue.

Espressif, who is responsible for the board package has made breaking changes in the latest version and your Copilot might have based the code on an earlier version.

Note:
I'm talking about the version of the board package, not the version of the IDE.

Thank you for the suggestion sterretje.

I'll give that a try tonight and post the results.

Couldn't find SMTP_Config in the list of keywords for that email library.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.