Home › Forums › The libraries hosted on the site › EMailSender send email with attachments › WiFiManager and Wemos d1 esp8266 sending mail problem
- This topic has 15 replies, 2 voices, and was last updated 3 years, 2 months ago by
Renzo Mischianti.
-
AuthorPosts
-
-
28 February 2022 at 16:15 #18969
Total newbie here. I just can’t figure out why I can’t connect to the smtp server. I have used the app password. Can someone take a look for me? here is my code. Thanks for the assist
#include <WiFiClient.h> #include <WiFiManager.h> //https://github.com/tzapu/WiFiManager #include <TimeLib.h> #include <ESP8266WiFi.h> #include <ESP8266WebServer.h> #include <strings_en.h> #include <ESP8266mDNS.h> #include <ESP_EEPROM.h> #include "Arduino.h" //wifi,email, internet #include <EMailSender.h> //#include <ArduinoJson.h> // #include "mainPage.h" #include <Wire.h> #include <Beastdevices_INA3221.h> //Wifi setting #define AP_SSID "custom" // custom filter roller SSID #define AP_PWD "1234567890" // custom passowrd ESP8266WebServer server(80); WiFiManager wm; char email_to[32] = ""; char email_login[32] = ""; //these are stored in EEPROM after input from web char email_password[32] = ""; EMailSender emailSend(email_login, email_password); void setup() { EEPROM.begin (120); //Wifi setup WiFi.mode(WIFI_STA); //set wifi toSTA;default STA+AP wm.setConfigPortalBlocking(false); wm.setConfigPortalTimeout(60); //automatically connect using saved credentials if they exist //If connection fails it starts an access point with the specified name // check if stored connection info is correct if (wm.autoConnect(AP_SSID, AP_PWD)) { Serial.println("\Connection data is correct!"); Serial.println(WiFi.localIP()); } else { Serial.println("\Connection data is incorrect…"); } //wm.startConfigPortal(); EMailSender::EMailMessage message; message.subject = "Float sensor may be stuck"; message.message = "Float sensor may be stuck, motor disabled until float sensor is resetted"; EMailSender::Response resp = emailSend.send(email_to, message); Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); };
-
This topic was modified 1 year, 9 months ago by
Renzo Mischianti.
-
This topic was modified 1 year, 9 months ago by
-
28 February 2022 at 22:14 #18979
Hi Claudacate,
can you send me the Serial output, the name of the provider and I must verify If WiFiManager set the DNS also or like some time ago It has a problem with the setting of DNS.How to manage dynamic WIFI configuration on esp8266 or esp32
Bye Renzo
-
1 March 2022 at 00:05 #18986
Thank you for replying. I think WifiManager set the DNS, but I am not sure. I will read up on the link you provided. Here is the serial output:
wm:[1] AutoConnect: SUCCESS
*wm:[1] STA IP Address: 192.168.88.217
Connection data is correct!
192.168.88.217
HTTP server started
ONLY ONE RECIPIENTmiltiple destination and attachments
Insecure client:0
smtp.gmail.com
465
Sending status:
0
2
Could not connect to mail server -
1 March 2022 at 04:54 #18987
I read your link. I did not use your version of the Wi-Fimanager library. I think that is the problem. Do I just swap the whole library? Or should I change a file? Thanks
-
1 March 2022 at 07:47 #18989
Hi Claudcate,
wait, first try to send an email with standard WiFi management.
Give me a feedback.
Bye Renzo -
1 March 2022 at 14:46 #19049
I used the standard WiFi management and EMailSenderEsp8266GMailTest.ino and still I can’t get a connection. Here is the serial monitor output. Hopefully you can make sense of it. Thank you
Connecting to Tea King
…………….
Connection: ESTABLISHED
Got IP address: 192.168.88.217
ONLY ONE RECIPIENTmiltiple destination and attachments
Insecure client:0
smtp.gmail.com
465
Sending status:
0
2
Could not connect to mail server -
2 March 2022 at 11:12 #19054
Hi, claudcate,
try to do a telnet to
smtp.gmail.com 465
so you can check if you have a firewall that blocks your outgoing connection.Bye Renzo
-
2 March 2022 at 16:32 #19065
Hi, I have tried the following. 1. I have used my iPhone’s hotspot as a wifi source since my home network may have possible network problem such as firewall. Result: same error as before. 2. I have spoofed my email address to see if I get different error code. Result: same error as before. 3. telnet to smtp.gmail.com 25 result: telnet smtp.gmail.com 25
Trying 142.251.8.108…
Connected to smtp.gmail.com.
Escape character is ‘^]’.
220 smtp.gmail.com ESMTP z11-20020a17090a1fcb00b001bc58804974sm5738172pjz.27 – gsmtp4. telnet to smtp.gmail.com 465. Result: telnet smtp.gmail.com 465
Trying 142.251.8.108…
Connected to smtp.gmail.com.
Escape character is ‘^]’.
Connection closed by foreign host. -
2 March 2022 at 16:40 #19066
However, upon further research. It seems port 465 requires SSL to connect. I used openssl and below is result. I think I am missing SSL in the code
openssl s_client -connect smtp.gmail.com:465
CONNECTED(00000005)
depth=3 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
verify return:1
depth=2 C = US, O = Google Trust Services LLC, CN = GTS Root R1
verify return:1
depth=1 C = US, O = Google Trust Services LLC, CN = GTS CA 1C3
verify return:1
depth=0 CN = smtp.gmail.com
verify return:1Here is the EMailSenderEsp8266GMailTest.ino I used
#include "Arduino.h" #include <EMailSender.h> #include <ESP8266WiFi.h> const char *ssid = "hotspot"; const char *password = "12345678"; uint8_t connection_state = 0; uint16_t reconnect_interval = 10000; EMailSender emailSend("sendemailfrom@gmail.com", "passworddfdf"); 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<br>io bene.<br>www.mischianti.org"; EMailSender::Response resp = emailSend.send("hcubeh@yahoo.com", message); Serial.println("Sending status: "); Serial.println(resp.status); Serial.println(resp.code); Serial.println(resp.desc); } void loop() { }
-
3 March 2022 at 13:35 #19072
I found my mistake! When I read the tutorial I followed the instruction for esp8266 core 2.4.2 and changed the emailsenderkey.h. I feel silly. Sorry I took up so much your time Renzo. Thanks again for your help.
-
3 March 2022 at 14:51 #19073
I know this is not part of your library, but was wondering if you can help. I recorded my email and password in EEProm, but when the value are used to login I can’t login. However, if I placed the value like char email_login[32]= “claudacate@gmail.com” I’d have no problem. I serial print out the value they looked identical. Here is what I used to update my email and password. Thank you
char email_login[32]; char email_password[32]; void loademail() { EEPROM.get(0, email_to); EEPROM.get(0 + sizeof(email_to), email_login); EEPROM.get(0 + sizeof(email_to) + sizeof(email_login), email_password); char ok[3]; EEPROM.get( 0 + sizeof(email_to) + sizeof(email_login) + sizeof(email_password), ok); if (String(ok) != String(“OK”)) { email_to[0] = 0; email_login[0] = 0; email_password[0] = 0; } } void saveemail() { EEPROM.put(0, email_to); EEPROM.put(0 + sizeof(email_to), email_login); EEPROM.put(0 + sizeof(email_to) + sizeof(email_login), email_password); char ok[3] = “OK”; EEPROM.put( 0 + sizeof(email_to) + sizeof(email_login) + sizeof(email_password), ok); EEPROM.commit(); }
-
3 March 2022 at 15:38 #19076
Hi Claudecate,
probably there are spaces added to the end of string to grow all byte array lengthTry something similar to
int writeStringToEEPROM(int addrOffset, const String &strToWrite) { byte len = strToWrite.length(); EEPROM.write(addrOffset, len); for (int i = 0; i < len; i++) { EEPROM.write(addrOffset + 1 + i, strToWrite[i]); } return addrOffset + 1 + len; } int readStringFromEEPROM(int addrOffset, String *strToRead) { int newStrLen = EEPROM.read(addrOffset); char data[newStrLen + 1]; for (int i = 0; i < newStrLen; i++) { data[i] = EEPROM.read(addrOffset + 1 + i); } data[newStrLen] = '\0'; *strToRead = String(data); return addrOffset + 1 + newStrLen; }
where the addrOffset is the start of eeprom and you can use String variable
String user = "ciccio"; String password = "passwd"; writeStringToEEPROM(0, user); writeStringToEEPROM(32, password);
and to read
String user; String password; readStringFromEEPROM(0, &user); readStringFromEEPROM(32, &password);
Bye Renzo
-
-
3 March 2022 at 15:12 #19074
Hi Claudacate,
I do a lot of tests (with core 2.7 and 3.0), but no problem with WeMos D1.Do you have to change some settings on EMailSenderKey?
Bye Renzo
-
3 March 2022 at 15:17 #19075
Ahhh ok..
Too late 😛
-
-
3 March 2022 at 16:16 #19077
Thank you for your help. I really appreciate it.
However,when I change the variable from char to String, I’d get error message
testemail:14:50: error: no matching function for call to ‘EMailSender::EMailSender(String&, String&)’
14 | EMailSender emailSend(email_login, email_password); -
3 March 2022 at 16:36 #19082
Try
EMailSender emailSend(email_login.c_str(), email_password.c_str());
Bye Renzo
-
-
AuthorPosts
- You must be logged in to reply to this topic.