This commit is contained in:
1 parent
d1c4de2930
commit
68fdf0b12d
1 file changed
+73
@@ -0,0 +1,73 @@
|
|||||||
|
#define ESP_MAIL_DISABLE_SD // Verhindert den SD-Fehler von vorhin
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <ESP_Mail_Client.h>
|
||||||
|
|
||||||
|
#define SMTP_HOST "smtp.gmail.com"
|
||||||
|
#define SMTP_PORT 587 // TLS Port
|
||||||
|
|
||||||
|
SMTPSession smtp;
|
||||||
|
|
||||||
|
// Callback-Funktion: Hier werden Fehler und Statusmeldungen ausgegeben
|
||||||
|
void smtpCallback(SMTP_Status status);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println();
|
||||||
|
|
||||||
|
// 1. WLAN Verbindung mit Status-Ausgabe
|
||||||
|
WiFi.begin("Wayne Manor", "einfach10zeichen!");
|
||||||
|
Serial.print("Verbinde mit WLAN");
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
Serial.print(".");
|
||||||
|
delay(500);
|
||||||
|
}
|
||||||
|
Serial.println("\nWLAN verbunden!");
|
||||||
|
Serial.print("IP-Adresse: ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
// 2. Debug-Level erhöhen (zeigt den Dialog mit dem Server im Monitor)
|
||||||
|
smtp.debug(1);
|
||||||
|
|
||||||
|
// 3. Callback registrieren
|
||||||
|
smtp.callback(smtpCallback);
|
||||||
|
|
||||||
|
Session_Config config;
|
||||||
|
config.server.host_name = SMTP_HOST;
|
||||||
|
config.server.port = SMTP_PORT;
|
||||||
|
config.login.email = "bruno.eckhardt07@gmail.com";
|
||||||
|
config.login.password = "qrwj rnqp qoks qzpy";
|
||||||
|
config.time.ntp_server = "pool.ntp.org"; // Gmail braucht oft eine korrekte Uhrzeit
|
||||||
|
config.time.gmt_offset = 1;
|
||||||
|
config.time.day_light_offset = 1;
|
||||||
|
|
||||||
|
SMTP_Message message;
|
||||||
|
message.sender.name = "ESP8266";
|
||||||
|
message.sender.email = "bruno.eckhardt07@gmail.com";
|
||||||
|
message.subject = "Test Mail!";
|
||||||
|
message.addRecipient("Empfänger", "bruno.eckhardt07@gmail.com"); // <-- Hier echte Ziel-E-Mail eintragen!
|
||||||
|
message.text.content = "Test Body vom ESP8266";
|
||||||
|
|
||||||
|
// 4. Verbindung und Versand mit Fehlermeldung
|
||||||
|
if (!smtp.connect(&config)) {
|
||||||
|
Serial.printf("Verbindung zum SMTP-Server fehlgeschlagen: %s\n", smtp.errorReason().c_str());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MailClient.sendMail(&smtp, &message)) {
|
||||||
|
Serial.printf("Fehler beim Senden der Mail: %s\n", smtp.errorReason().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Bleibt leer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Definition der Callback-Funktion
|
||||||
|
void smtpCallback(SMTP_Status status) {
|
||||||
|
Serial.println(status.info());
|
||||||
|
if (status.success()) {
|
||||||
|
Serial.println("----------------");
|
||||||
|
Serial.println("E-Mail erfolgreich gesendet!");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user