Replies: 1 comment
-
Nothing I can help. You should debug your code. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
Could someone help me with my code to send email when I get an alert to an ESP32-C3 from an ESP32-S3, with serial connection? Here is my code: Thank you in advance.
#include <Arduino.h>
#include <WiFi.h>
#include <ESP_Mail_Client.h>
#define WIFI_SSID ""
#define WIFI_PASSWORD ""
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 465
/* The sign in credentials /
#define AUTHOR_EMAIL ""
#define AUTHOR_PASSWORD "*"
/* Recipient's email*/
#define RECIPIENT_EMAIL "****"
/* The SMTP Session object used for Email sending */
SMTPSession smtp;
/* Declare the message class */
SMTP_Message message;
/* Declare the session config data */
ESP_Mail_Session session;
/* Callback function to get the Email sending status */
void smtpCallback(SMTP_Status status);
//************************************************************************************************
HardwareSerial networkGateway(1); //Serial connection setup between network gateway & receiver.
char RxdChar = networkGateway.read(); //This is the data to be read, sent by the networkReceiver
String alertCode;
//************************************************************************************************
void setup() {
//Serial.begin(Buad Rate, Data Protocol, Txd pin = GPIO21, Rxd pin = GPIO20);
networkGateway.begin(115200, SERIAL_8N1, 21, 20);
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
//*******************************************************************************************************************
void sendMail() {
/* Enable the debug via Serial port */
smtp.debug(1);
/* Set the callback function to get the sending results */
smtp.callback(smtpCallback);
/* Set the session config */
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.login.user_domain = "";
/* Set the message headers /
message.sender.name = F("");
message.sender.email = AUTHOR_EMAIL;
message.subject = F("Home Alert Test");
message.addRecipient("*", RECIPIENT_EMAIL);
switch(RxdChar) {
case 71:
alertCode = "Garage Opened";
break;
case 70:
alertCode = "Garage Closed";
break;
}
String textMsg = alertCode;
message.text.content = textMsg;
message.text.charSet = F("us-ascii");
message.text.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_low;
message.response.notify = esp_mail_smtp_notify_success | esp_mail_smtp_notify_failure | esp_mail_smtp_notify_delay;
smtp.debug(1);
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
/* Start sending Email and close the session */
if (!MailClient.sendMail(&smtp, &message)) {
Serial.println("Error sending Email, " + smtp.errorReason());
}
else {
Serial.println("Email sent!");
}
}
//**************************************************************************************************************
void loop(){
while(networkGateway.available() == 0) {
char RxdChar = networkGateway.read();
switch(RxdChar) {
case 71:
alertCode = "Garage Opened";
break;
case 70:
alertCode = "Garage Closed";
break;
}
smtp.debug(1);
/* Connect to server with the session config */
if (!smtp.connect(&session))
return;
}
}
Beta Was this translation helpful? Give feedback.
All reactions