#include "ESP32_MailClient.h"
// REPLACE WITH YOUR NETWORK CREDENTIALS
const char* ssid = "SINHVIEN";
const char* password = "";
#define emailSenderAccount "[email protected]"
#define emailSenderPassword "abc@123"
#define emailRecipient "[email protected]"
#define smtpServer "smtp.gmail.com"
#define smtpServerPort 465
#define emailSubject "NodeWifi32 Test"
// The Email Sending data object contains config and data to send
SMTPData smtpData;
// Callback function to get the Email sending status
void sendCallback(SendStatus info);
void setup(){
Serial.begin(115200);
Serial.println();
Serial.print("Connecting");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(200);
}
Serial.println();
Serial.println("WiFi connected.");
Serial.println();
Serial.println("Preparing to send email");
Serial.println();
// Set the SMTP Server Email host, port, account and password
smtpData.setLogin(smtpServer, smtpServerPort, emailSenderAccount, emailSenderPassword);
// Set the sender name and Email
smtpData.setSender("NodeWifi32", emailSenderAccount);
// Set Email priority or importance High, Normal, Low or 1 to 5 (1 is highest)
smtpData.setPriority("High");
// Set the subject
smtpData.setSubject(emailSubject);
// Set the message with HTML format
smtpData.setMessage("<div style=\"color:#2f4468;\"><h1>Hello World!</h1><p>- Sent from NodeWifi32 board</p></div>", true);
// Set the email message in text format (raw)
//smtpData.setMessage("Hello World! - Sent from NodeWifi32 board", false);
// Add recipients, you can add more than one recipient
smtpData.addRecipient(emailRecipient);
//smtpData.addRecipient("[email protected]");
smtpData.setSendCallback(sendCallback);
//Start sending Email, can be set callback function to track the status
if (!MailClient.sendMail(smtpData))
Serial.println("Error sending Email, " + MailClient.smtpErrorReason());
//Clear all data from Email object to free memory
smtpData.empty();
}
void loop()
{
}
// Callback function to get the Email sending status
void sendCallback(SendStatus msg) {
// Print the current status
Serial.println(msg.info());
// Do something when complete
if (msg.success()) {
Serial.println("----------------");
}
}