Hello Renzo,
First of all, thank you very much for this great solution. As far as I've been able to tell so far, your solution is the only one which is working with all SMTP servers.
However, I have a problem with the smtp.gmail.com server when using Tzapu's WifiManager library (https://github.com/tzapu/WiFiManager) with your library together. In this case, the sending of the e-mails with the gmail stmp server are no longer working. Without this library (WiFiManager) the sending of the e-mails are working well.
So when I add those two lines, the sending of emails with the smtp server "smtp.gmail.com" no longer works:
#include // https://github.com/tzapu/WiFiManager
WiFiManager wifiManager;
Hier is my Code (I just took your sample and made some changes:
/*
* EMailSender library for Arduino, esp8266 and esp32
* Simple esp8266 Gmail with Email From name send example
*
* http://mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
*
*/
#include "Arduino.h"
#include
#include
#include // https://github.com/tzapu/WiFiManager
const char *ssid = "SSID";
const char *password = "SSID_PASSWORD";
uint8_t connection_state = 0;
uint16_t reconnect_interval = 10000;
const char *smtp_server = "smtp.gmail.com";
uint16_t smtp_port = 465;
const char *email_login = "GMAIL_USER@gmail.com";
const char *email_password = "GMAIL_PASSWORD";
const char *email_from = "EMAIL_FROM@gmail.com";
const char *email_to = "EMAIL_TO@gmail.com";
const char *email_subject =
"Device DEVICE_NAME alerts water alarm!";
WiFiManager wifiManager;
EMailSender emailSend(email_login, email_password, email_from, smtp_server,
smtp_port);
uint8_t WiFiConnect(const char *nSSID = nullptr,
const char *nPassword = nullptr) {
static uint16_t attempt = 0;
Serial.print("Connecting to ");
if (nSSID) {
WiFi.begin(nSSID, nPassword);
Serial.println(nSSID);
}
uint8_t i = 0;
while(WiFi.status()!= WL_CONNECTED &&
i++ < 50 ) { delay(200); Serial.print("."); } ++attempt; Serial.println(""); if (i == 51) { Serial.print("Connection: TIMEOUT on attempt: "); Serial.println(attempt); if (attempt % 2 == 0) Serial.println( "Check if access point available or SSID and Password\r\n"); return false; } Serial.println("Connection: ESTABLISHED"); Serial.print("Got IP address: "); Serial.println(WiFi.localIP()); return true; } void Awaits() { uint32_t ts = millis(); while (!connection_state) { delay(50); if(millis() > (ts + reconnect_interval) && !connection_state) {
connection_state = WiFiConnect();
ts = millis();
}
}
}
void setup() {
Serial.begin(115200);
connection_state = WiFiConnect(ssid, password);
if (!connection_state) // if not connected to WIFI
Awaits(); // constantly trying to connect
EMailSender::EMailMessage message;
message.subject = "Soggetto";
message.message = "Ciao come stai
io bene.
www.mischianti.org";
EMailSender::Response resp = emailSend.send(email_to, message);
Serial.println("Sending status: ");
Serial.println(resp.status);
Serial.println(resp.code);
Serial.println(resp.desc);
}
void loop() {
}
It doesn't matter if I use the functions of this library or not. It is enough if I just speak to this library. But other servers seem to be working. It looks like the problem is only happening with gmail's stmp server.
Or am I doing something wrong?
Best regards