Comments (4)
Not like that, whats the syntax for that library what are you suppose to be passing to it ?
You probably need to make your own webclient obj
from wifimanager.
This is sample code from their examples/SMTP/External_Client/Generic/Generic.io
// Your network client class object e.g. WiFiClient, EthernetClient and GSMClient
NetworkClient net_client;
I replaced Network Client with WiFiManager and net_client with wm so my code is:
WiFiManager wm;
The link to this example code is
[examples/SMTP/External_Client/Generic](url)
Line 44 and 83
here is my code:
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <WiFiManager.h>
#include <ESP_Mail_Client.h>
#define SMTP_HOST "xxxxxxxxxxxxx"
#define SMTP_PORT esp_mail_smtp_port_587
#define AUTHOR_EMAIL "xxxxxxxxxxxxxm"
#define AUTHOR_PASSWORD "xxxxxxxxxxx"
#define RECIPIENT_EMAIL "xxxxxxxxxx"
// // put function declarations here:
// int myFunction(int, int);
int upone = 0;
SMTPSession smtp;
// Your network client class object e.g. WiFiClient, EthernetClient and GSMClient
WiFiManager wm;
void networkConnection()
{
// Neywork connection code here
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
// WiFiManager wm;
// reset settings - wipe stored credentials for testing
// these are stored by the esp library
// wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
// res = wm.autoConnect("AutoConnectAP"); // anonymous ap
res = wm.autoConnect("AutoConnectAP"); // password protected ap
if(!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
}
// Define the callback function to handle server status acknowledgement
void networkStatusRequestCallback()
{
// Set the network status based on your network client
smtp.setNetworkStatus(true /* or false */);
}
void smtpCallback(SMTP_Status status);
void setup() {
// WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// it is a good practice to make sure your code sets wifi mode how you want it.
// put your setup code here, to run once:
Serial.begin(115200);
networkConnection();
MailClient.networkReconnect(true);
smtp.debug(1);
smtp.callback(smtpCallback);
Session_Config config;
config.server.host_name = SMTP_HOST;
config.server.port = SMTP_PORT;
config.login.email = AUTHOR_EMAIL;
config.login.password = AUTHOR_PASSWORD;
config.login.user_domain = F("127.0.0.1");
config.time.ntp_server = F("pool.ntp.org,time.nist.gov");
smtp.setClient(&wm);
smtp.networkStatusRequestCallback(networkStatusRequestCallback);
smtp.networkConnectionRequestCallback(networkConnection);
if (!smtp.connect(&config))
{
MailClient.printf("Connection error, Status Code: %d, Error Code: %d, Reason: %s\n", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
return;
}
if (!smtp.isLoggedIn())
{
Serial.println("Error, Not yet logged in.");
}
else
{
if (smtp.isAuthenticated())
Serial.println("Successfully logged in.");
else
Serial.println("Connected with no Auth.");
}
SMTP_Message message;
message.sender.name = F("ESP Mail");
message.sender.email = AUTHOR_EMAIL;
message.subject = F("Test sending plain text Email");
message.addRecipient(F("Someone"), RECIPIENT_EMAIL);
message.text.content = "This is simple plain text message";
if (!MailClient.sendMail(&smtp, &message))
MailClient.printf("Error, Status Code: %d, Error Code: %d, Reason: %s\n", smtp.statusCode(), smtp.errorCode(), smtp.errorReason().c_str());
MailClient.printf("Free Heap: %d\n", MailClient.getFreeHeap());
}
void loop() {
Serial.print("Loop waiting:");
Serial.println(upone);
delay(1000);
upone++;
}
void smtpCallback(SMTP_Status status)
{
Serial.println(status.info());
if (status.success())
{
Serial.println("----------------");
MailClient.printf("Message sent success: %d\n", status.completedCount());
MailClient.printf("Message sent failed: %d\n", status.failedCount());
Serial.println("----------------\n");
for (size_t i = 0; i < smtp.sendingResult.size(); i++)
{
SMTP_Result result = smtp.sendingResult.getItem(i);
MailClient.printf("Message No: %d\n", i + 1);
MailClient.printf("Status: %s\n", result.completed ? "success" : "failed");
MailClient.printf("Date/Time: %s\n", MailClient.Time.getDateTimeString(result.timestamp, "%B %d, %Y %H:%M:%S").c_str());
MailClient.printf("Recipient: %s\n", result.recipients.c_str());
MailClient.printf("Subject: %s\n", result.subject.c_str());
}
Serial.println("----------------\n");
smtp.sendingResult.clear();
}
}
Thank you for your help.
from wifimanager.
Wm doesn't replace wifi client, you will have to use the mail constructor without a wifi connection and use wm before hand. Or use the regular one and handle wm before that if
from wifimanager.
Got it. Thank you.
from wifimanager.
Related Issues (20)
- Add support for simultaneo use whit ESPAsyncWebServer.h HOT 4
- Add better detection for wrong password failures HOT 1
- Esp8266 and deep sleep mode
- ESP32 Automatic Network Mode Switching with Arduino Sketch Troubleshooting HOT 7
- Avoid compiler warning. Wrong specifier used for printf statement. HOT 3
- error Exception (3) on ESP8266 with version 2.0.17 and not 2.0.16 HOT 5
- Custom page addition matching current layout and format
- If anyone wants to change the name (SSID) of the Access Point (AP) that appears (with the IP address 192.168.4.1) HOT 12
- Possibility to change pass for SoftAP from webui.
- Feature configurable? WiFi AP started when local WiFi is down HOT 2
- How to save and restore Ip adress from webportal ?
- Dedicated Parameter Page HOT 1
- Unable to save/retrieve custom variables in WiFiManager
- Q: ESP Reboot after successful initial connection to own wifi possible (bind issue with Async Webserver from AP to STA)
- Esp32 wroom 32 UE
- Question: Is there a way to detect if the WiFi connection is successful before the config portal closes? HOT 1
- Force remove DNS input from Captive portal
- Question: Is possible change deep link to redirect to an App instead of Captive Portal HOT 3
- Add new Release to platformio HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wifimanager.