#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
const char* ssid = "YourWiFiNetworkName";
const char* password = "YourWiFiPassword";
const char* smtpServer = "smtp.gmail.com";
const int smtpPort = 465;
const char* email = "your_email@gmail.com";
const char* password = "your_email_password";
const char* recipient = "recipient_email@example.com";
void setup() {
Serial.begin(115200);
delay(10);
// Connect to Wi-Fi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
WiFiClientSecure client;
if (client.connect(smtpServer, smtpPort)) {
Serial.println("Connected to SMTP server");
client.println("EHLO " + WiFi.localIP().toString());
client.println("AUTH LOGIN");
client.println(base64::encode(email));
client.println(base64::encode(password));
client.println("MAIL FROM:<" + String(email) + ">");
client.println("RCPT TO:<" + String(recipient) + ">");
client.println("DATA");
client.println("Subject: Test Email from ESP8266");
client.println();
client.println("This is a test email sent from an ESP8266!");
client.println(".");
client.println("QUIT");
Serial.println("Email sent");
} else {
Serial.println("Failed to connect to SMTP server");
}
delay(60000); // Send email every minute (for example)
}
|