These are the codes I put on arduino ide and I also want to add whenever the rfid get scans the card it will send email with different messages. Though, I'm not there yet since I'm trying to make it success for 1time. The problem is that on Serial Monitor/actual upload, it won't trigger or do what I want and what only shows on SM is purely all DOTS ....
Help me solve/correct these since I need to make it asap.
CODES:
#include <Arduino.h>
#if defined(ESP32)
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#include <ESP8266WiFi.h>
#else
#endif
#include <SPI.h>
#include <MFRC522.h>
#include <ESP_Mail_Client.h>
#define WIFI_SSID "SSID"
#define WIFI_PASSWORD "PASS"
#define SMTP_HOST "smtp.gmail.com"
#define SMTP_PORT 465
#define AUTHOR_EMAIL "SENDER@gmail.com"
#define AUTHOR_PASSWORD "SendPassword"
#define RST_PIN D3
#define SS_PIN D4
MFRC522 mfrc522(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
MFRC522::StatusCode status;
SMTPSession smtp;
void smtpCallback(SMTP_Status status);
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.print("Connecting to AP");
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(1000);
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
MailClient.networkReconnect(true);
}
void loop()
{
if ( ! mfrc522.PICC_IsNewCardPresent())
{
return;
}
String content= "";
if (content.substring(1) == "54 6F 63 A1"){
Serial.println("Check-In Card Scanned");
SendEmail("This is the text for the check-in button email", "Check-In Subject"); //Edit with your message text
}
}
void SendEmail(String htmlMsg, String MessageSubject)
{
smtp.debug(1);
smtp.callback(smtpCallback);
ESP_Mail_Session session;
session.server.host_name = SMTP_HOST;
session.server.port = SMTP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;
session.time.ntp_server = F("pool.ntp.org,time.nist.gov");
session.time.gmt_offset = -5;
session.time.day_light_offset = 0;
SMTP_Message message;
message.sender.name = F("SenderRF");
message.sender.email = AUTHOR_EMAIL;
message.subject = MessageSubject;
message.addRecipient(F("CPps"), F("Receiver@gmail.com"));
message.html.content = htmlMsg;
message.html.charSet = F("us-ascii");
message.html.transfer_encoding = Content_Transfer_Encoding::enc_7bit;
message.priority = esp_mail_smtp_priority::esp_mail_smtp_priority_normal;
if (!smtp.connect(&session))
Serial.println("Error connecting to SMTP server, " + smtp.errorReason());
if (!MailClient.sendMail(&smtp, &message))
{
Serial.println("Error sending Email, " + smtp.errorReason());
Serial.println("Turning on Red LED");
}
}
void smtpCallback(SMTP_Status status)
{
Serial.println(status.info());
if (status.success())
{
Serial.println("----------------");
ESP_MAIL_PRINTF("Message sent success: %d\n", status.completedCount());
ESP_MAIL_PRINTF("Message sent failed: %d\n", status.failedCount());
Serial.println("----------------\n");
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
SMTP_Result result = smtp.sendingResult.getItem(i);
ESP_MAIL_PRINTF("Message No: %d\n", i + 1);
ESP_MAIL_PRINTF("Status: %s\n", result.completed ? "success" : "failed");
ESP_MAIL_PRINTF("Recipient: %s\n", result.recipients.c_str());
ESP_MAIL_PRINTF("Subject: %s\n", result.subject.c_str());
}
Serial.println("----------------\n");
smtp.sendingResult.clear();
}
}