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, 4 months ago by Renzo Mischianti.
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.
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
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
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
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 – gsmtp
4. 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.
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:1
Here 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() {
}
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.
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
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);
Maintaining a repository (or site or forum) is a lot like tending to a garden - it requires constant care and attention to keep it thriving. If you're a skilled gardener (or coder!) and want to help keep our repository blooming, we'd love to have you on board! We're also looking for talented writers and forum moderators to help us grow our community. Interested in joining our team? Don't hesitate to reach out and let us know how you can contribute!
Are you a fan of electronics or programming? Share your knowledge with others, write a simple tutorial or how to make a great project Contact me: share_your_ideas@mischianti.org
The content displayed on this website is protected under a CC BY-NC-ND license. Visitors are prohibited from using, redistributing, or altering any content from this website for commercial purposes, including generating revenue through advertising. Any unauthorized use is a violation of the license terms and legal action may be taken against individuals or entities found to be in violation.
You must also provide the link to the source.