初始化提交
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* Arduino Mega and UIPEthernet send example with attach
|
||||
* this example is not tested for all, I can't find a provider
|
||||
* that manage attach without SSL and TLS
|
||||
*
|
||||
* Pay attention you must set in the library
|
||||
* #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_ENC28J60
|
||||
* for UIPEthernet
|
||||
*
|
||||
* #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100
|
||||
* for standard Ethernet
|
||||
*
|
||||
* The base64 encoding of the image is slow, so be patient
|
||||
*
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <SPI.h>
|
||||
#include <UIPEthernet.h>
|
||||
#include <SD.h>
|
||||
|
||||
#include <EMailSender.h>
|
||||
|
||||
// Enter a MAC address for your controller below.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
|
||||
// EMailSender(const char* email_login, const char* email_password, const char* email_from, const char* smtp_server, uint16_t smtp_port, bool isSecure = false);
|
||||
EMailSender emailSend("<LOGIN>", "<PASSWD>", "<EMAIL-FROM>", "<SMTP-SERVER>", "<SMTP-SERVER-PORT>");
|
||||
|
||||
void printDirectory(File dir, int numTabs);
|
||||
|
||||
//The setup function is called once at startup of the sketch
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Starting!");
|
||||
|
||||
Serial.print("Initializing SD card...");
|
||||
|
||||
if (!SD.begin(4)) {
|
||||
Serial.println("initialization failed!");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("initialization done.");
|
||||
|
||||
File root = SD.open("/");
|
||||
|
||||
printDirectory(root, 0);
|
||||
|
||||
Serial.println("done!");
|
||||
|
||||
// File myFile = SD.open("/TEST.TXT", "r");
|
||||
// if(myFile) {
|
||||
// myFile.seek(0);
|
||||
// DEBUG_PRINTLN(F("OK"));
|
||||
// myFile.close();
|
||||
// }
|
||||
// else {
|
||||
// DEBUG_PRINTLN(F("KO"));
|
||||
// }
|
||||
//
|
||||
//
|
||||
// start the Ethernet connection:
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
while(1);
|
||||
}
|
||||
Serial.print("IP address ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
|
||||
|
||||
EMailSender::EMailMessage message;
|
||||
message.subject = "Soggetto";
|
||||
message.message = "Ciao come stai<br>io bene.<br>www.mischianti.org";
|
||||
message.mime = MIME_TEXT_PLAIN;
|
||||
|
||||
// Two file
|
||||
// EMailSender::FileDescriptior fileDescriptor[2];
|
||||
// fileDescriptor[1].filename = F("test.txt");
|
||||
// fileDescriptor[1].url = F("/test.txt");
|
||||
// fileDescriptor[1].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
|
||||
//
|
||||
// fileDescriptor[0].filename = F("logo.jpg");
|
||||
// fileDescriptor[0].url = F("/logo.jpg");
|
||||
// fileDescriptor[0].mime = "image/jpg";
|
||||
// fileDescriptor[0].encode64 = true;
|
||||
// fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
|
||||
//
|
||||
// EMailSender::Attachments attachs = {2, fileDescriptor};
|
||||
|
||||
// One file
|
||||
EMailSender::FileDescriptior fileDescriptor[1];
|
||||
fileDescriptor[0].filename = F("test.txt");
|
||||
fileDescriptor[0].url = F("/test.txt");
|
||||
fileDescriptor[0].mime = MIME_TEXT_PLAIN;
|
||||
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
|
||||
|
||||
// Pay attention base64 encoding is quite slow
|
||||
// EMailSender::FileDescriptior fileDescriptor[2];
|
||||
// fileDescriptor[0].filename = F("logo.jpg");
|
||||
// fileDescriptor[0].url = F("/logo.jpg");
|
||||
// fileDescriptor[0].mime = "image/jpg";
|
||||
// fileDescriptor[0].encode64 = false;
|
||||
// fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SD;
|
||||
|
||||
EMailSender::Attachments attachs = {1, fileDescriptor};
|
||||
|
||||
EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message, attachs);
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
|
||||
File root2 = SD.open("/");
|
||||
|
||||
printDirectory(root2, 0);
|
||||
|
||||
Serial.println("done!");
|
||||
SD.end();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void printDirectory(File dir, int numTabs) {
|
||||
while (true) {
|
||||
|
||||
File entry = dir.openNextFile();
|
||||
if (! entry) {
|
||||
// no more files
|
||||
break;
|
||||
}
|
||||
for (uint8_t i = 0; i < numTabs; i++) {
|
||||
Serial.print('\t');
|
||||
}
|
||||
Serial.print(entry.name());
|
||||
if (entry.isDirectory()) {
|
||||
Serial.println("/");
|
||||
printDirectory(entry, numTabs + 1);
|
||||
} else {
|
||||
// files have sizes, directories do not
|
||||
Serial.print("\t\t");
|
||||
Serial.println(entry.size(), DEC);
|
||||
}
|
||||
entry.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,2 @@
|
||||
Prova prova prova
|
||||
www.mischianti.org
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* Arduino Mega and UIPEthernet send example with Sendgrid provider
|
||||
*
|
||||
* Pay attention you must set in the library
|
||||
* #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_ENC28J60
|
||||
* for UIPEthernet
|
||||
*
|
||||
* #define DEFAULT_EMAIL_NETWORK_TYPE_ARDUINO NETWORK_W5100
|
||||
* for standard Ethernet
|
||||
*
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <SPI.h>
|
||||
#include <UIPEthernet.h>
|
||||
|
||||
#include <EMailSender.h>
|
||||
|
||||
// Enter a MAC address for your controller below.
|
||||
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
|
||||
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
|
||||
|
||||
EMailSender emailSend("<YOUR-SENDGRID-API-KEY>", "<YOUR-SENDGRID-PASSWD>", "<FROM-EMAIL>", "smtp.sendgrid.net", 25);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(115200);
|
||||
// while (!Serial) {}
|
||||
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Starting!");
|
||||
|
||||
// start the Ethernet connection:
|
||||
if (Ethernet.begin(mac) == 0) {
|
||||
Serial.println("Failed to configure Ethernet using DHCP");
|
||||
while(1);
|
||||
}
|
||||
Serial.print("IP address ");
|
||||
Serial.println(Ethernet.localIP());
|
||||
|
||||
|
||||
EMailSender::EMailMessage message;
|
||||
message.subject = "Soggetto";
|
||||
message.message = "Ciao come stai<br>io bene.<br>www.mischianti.org";
|
||||
|
||||
EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message);
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* Simple esp32 Gmail send to a distribution list example
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <EMailSender.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
uint8_t connection_state = 0;
|
||||
uint16_t reconnect_interval = 10000;
|
||||
|
||||
EMailSender emailSend("<YOUR-SMTP>", "<YOUR-SMTP-PASSWD>");
|
||||
|
||||
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);
|
||||
const char* ssid = "<YOUR-SSID>";
|
||||
const char* password = "<YOUR-PASSWD>";
|
||||
|
||||
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";
|
||||
|
||||
// Send to 3 different email
|
||||
const char* arrayOfEmail[] = {"<FIRST>@gmail.com", "<SECOND>@yahoo.com", "<THIRD>@hotmail.com"};
|
||||
EMailSender::Response resp = emailSend.send(arrayOfEmail, 3, message);
|
||||
|
||||
// // Send to 3 different email, 2 in C and 1 in CC
|
||||
// const char* arrayOfEmail[] = {"<FIRST>@gmail.com", "<SECOND>@yahoo.com", "<THIRD>@hotmail.com"};
|
||||
// EMailSender::Response resp = emailSend.send(arrayOfEmail, 2, 1, message);
|
||||
//
|
||||
// // Send to 3 different email first to C second to CC and third to CCn
|
||||
// const char* arrayOfEmail[] = {"<FIRST>@gmail.com", "<SECOND>@yahoo.com", "<THIRD>@hotmail.com"};
|
||||
// EMailSender::Response resp = emailSend.send(arrayOfEmail, 3, message);
|
||||
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* esp32 Gmail send example with 2 attach loaded in SPIFFS
|
||||
*
|
||||
* The base64 encoding of the image is slow, so be patient
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <EMailSender.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include <SPIFFS.h>
|
||||
|
||||
const char* ssid = "<YOUR-SSID>";
|
||||
const char* password = "<YOUR-PASSWD>";
|
||||
|
||||
uint8_t connection_state = 0;
|
||||
uint16_t reconnect_interval = 10000;
|
||||
|
||||
EMailSender emailSend("account_gmail@gmail.com", "<YOUR-GMAIL-PASSWD>");
|
||||
|
||||
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);
|
||||
|
||||
if(!SPIFFS.begin()){
|
||||
Serial.println("An Error has occurred while mounting SPIFFS");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("ReadDir");
|
||||
File dir = SPIFFS.open("/");
|
||||
File file = dir.openNextFile();
|
||||
while (file) {
|
||||
Serial.print(file.name());
|
||||
Serial.println(file.size());
|
||||
|
||||
file = dir.openNextFile();
|
||||
}
|
||||
|
||||
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::FileDescriptior fileDescriptor[2];
|
||||
fileDescriptor[1].filename = F("test.txt");
|
||||
fileDescriptor[1].url = F("/test.txt");
|
||||
fileDescriptor[1].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
|
||||
|
||||
fileDescriptor[0].filename = F("logo.jpg");
|
||||
fileDescriptor[0].url = F("/logo.jpg");
|
||||
fileDescriptor[0].mime = "image/jpg";
|
||||
fileDescriptor[0].encode64 = true;
|
||||
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
|
||||
|
||||
EMailSender::Attachments attachs = {2, fileDescriptor};
|
||||
|
||||
EMailSender::Response resp = emailSend.send("email_to_receive@gmail.com", message, attachs);
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,2 @@
|
||||
Prova prova prova
|
||||
www.mischianti.org
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* Simple esp32 Gmail send example
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <EMailSender.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
const char* ssid = "<YOUR-SSID>";
|
||||
const char* password = "<YOUR-PASSWD>";
|
||||
|
||||
uint8_t connection_state = 0;
|
||||
uint16_t reconnect_interval = 10000;
|
||||
|
||||
EMailSender emailSend("account_login@gmail.com", "<YOUR-GMAIL-PASSWD>");
|
||||
|
||||
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("receive_email@gmail.com", message);
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* esp8266 Gmail send example with 2 attach loaded in SPIFFS
|
||||
*
|
||||
* The base64 encoding of the image is slow, so be patient
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <EMailSender.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
uint8_t connection_state = 0;
|
||||
uint16_t reconnect_interval = 10000;
|
||||
|
||||
EMailSender emailSend("<smtp_account@gmail.com>", "<PASSWORD>");
|
||||
|
||||
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);
|
||||
const char* ssid = "<YOUR_SSID>";
|
||||
const char* password = "<YOUR_PASSWD>";
|
||||
|
||||
if(!SPIFFS.begin()){
|
||||
Serial.println("An Error has occurred while mounting SPIFFS");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("ReadDir");
|
||||
Dir dir = SPIFFS.openDir("/");
|
||||
while (dir.next()) {
|
||||
Serial.print(dir.fileName());
|
||||
if(dir.fileSize()) {
|
||||
File f = dir.openFile("r");
|
||||
Serial.println(f.size());
|
||||
}
|
||||
}
|
||||
|
||||
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::FileDescriptior fileDescriptor[2];
|
||||
fileDescriptor[1].filename = F("test.txt");
|
||||
fileDescriptor[1].url = F("/test.txt");
|
||||
fileDescriptor[1].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
|
||||
|
||||
fileDescriptor[0].filename = F("logo.jpg");
|
||||
fileDescriptor[0].url = F("/logo.jpg");
|
||||
fileDescriptor[0].mime = "image/jpg";
|
||||
fileDescriptor[0].encode64 = true;
|
||||
fileDescriptor[0].storageType = EMailSender::EMAIL_STORAGE_TYPE_SPIFFS;
|
||||
|
||||
EMailSender::Attachments attachs = {2, fileDescriptor};
|
||||
|
||||
EMailSender::Response resp = emailSend.send("<receipe@gmail.com>", message, attachs);
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -0,0 +1,2 @@
|
||||
Prova prova prova
|
||||
www.mischianti.org
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* EMailSender library for Arduino, esp8266 and esp32
|
||||
* Simple esp8266 Gmail send example
|
||||
*
|
||||
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <EMailSender.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
const char* ssid = "<YOUR-SSID>";
|
||||
const char* password = "<YOUR-PASSWD>";
|
||||
|
||||
uint8_t connection_state = 0;
|
||||
uint16_t reconnect_interval = 10000;
|
||||
|
||||
EMailSender emailSend("smtp.account@gmail.com", "password");
|
||||
|
||||
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("account_to_send@gmail.com", message);
|
||||
|
||||
Serial.println("Sending status: ");
|
||||
|
||||
Serial.println(resp.status);
|
||||
Serial.println(resp.code);
|
||||
Serial.println(resp.desc);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user