Home › Forums › esp8266 › The sending of the E-Mails with WifiManager and gmail smtp server not working
Tagged: EMailSender, WiFiManager
- This topic has 4 replies, 2 voices, and was last updated 4 years, 3 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
15 February 2021 at 14:13 #10012
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
-
This topic was modified 1 year, 10 months ago by
Renzo Mischianti.
-
This topic was modified 1 year, 10 months ago by
Renzo Mischianti.
-
This topic was modified 1 year, 10 months ago by
-
15 February 2021 at 14:41 #10019
Hi Tans,
you code not use WiFiManager, to use It you must do something like this/* * 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 *smtp_server = "smtp.gmail.com"; uint16_t smtp_port = 465; const char *email_login = "@gmail.com"; const char *email_password = ""; const char *email_from = "@gmail.com"; const char *email_to = "@gmail.com"; const char *email_subject = "Device {{DEVICE_AP}}/{{DEVICE_LOCATION}} alerts water alarm!"; WiFiManager wifiManager; EMailSender emailSend(email_login, email_password, email_from, smtp_server, smtp_port); void configModeCallback (WiFiManager *myWiFiManager) { Serial.println("Entered config mode"); Serial.println(WiFi.softAPIP()); //if you used auto generated SSID, print it Serial.println(myWiFiManager->getConfigPortalSSID()); } void setup() { Serial.begin(115200); //WiFiManager //Local intialization. Once its business is done, there is no need to keep it around WiFiManager wifiManager; //reset settings - for testing // wifiManager.resetSettings(); //set callback that gets called when connecting to previous WiFi fails, and enters Access Point mode wifiManager.setAPCallback(configModeCallback); //fetches ssid and pass and tries to connect //if it does not connect it starts an access point with the specified name //here "AutoConnectAP" //and goes into a blocking loop awaiting configuration if(!wifiManager.autoConnect("esp8266 mischiantis test")) { Serial.println("failed to connect and hit timeout"); //reset and try again, or maybe put it to deep sleep ESP.reset(); delay(1000); } //if you get here you have connected to the WiFi Serial.println(F("WIFIManager connected!")); Serial.print(F("IP --> ")); Serial.println(WiFi.localIP()); Serial.print(F("GW --> ")); Serial.println(WiFi.gatewayIP()); Serial.print(F("SM --> ")); Serial.println(WiFi.subnetMask()); Serial.print(F("DNS 1 --> ")); Serial.println(WiFi.dnsIP(0)); Serial.print(F("DNS 2 --> ")); Serial.println(WiFi.dnsIP(1)); 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() { }For additional detail you can check this guide
How to manage dynamic WIFI configuration on esp8266 or esp32
Bye Renzo
-
15 February 2021 at 15:14 #10024
Hello Renzo,
Thank you for your reponse!
Your code works only after the first call. WifiManager saves the WIFI access data and uses it for the next calles. After that, the sending of the e-mail no longer works. I have to delete WIFI access data beforehand so that the transmission works. That is not what I want. So I have to somehow make sure that your email sender can handle the fact that the access data can be saved beforehand. Or I have to deal with WifiManager in more detail.
Many Thanks!
Attachments:
You must be logged in to view attached files. -
15 February 2021 at 15:31 #10027
Hello Renzo,
That was my fault! It seems to work with your code.
Thank you very much!
-
-
15 February 2021 at 16:56 #10030
Perfect Tans,
I’m glad you found the problem.
Bye Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.