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:
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, 5 months ago by Renzo Mischianti.
This topic was modified 1 year, 5 months ago by Renzo Mischianti.
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() {
}
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.
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.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional
Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.