Skip to content

Commit 2dec3d3

Browse files
committed
Add example and library properties
1 parent ed09b78 commit 2dec3d3

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ Then check the response:
105105
Serial.println(resp.status);
106106
```
107107

108+
From version 2.1.1 new features distribution list to send CC and CCn email.
109+
108110
Example output:
109111

110112
```cpp
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* EMailSender library for Arduino, esp8266 and esp32
3+
* Simple esp32 Gmail send to a distribution list example
4+
*
5+
* https://www.mischianti.org/category/my-libraries/emailsender-send-email-with-attachments/
6+
*
7+
*/
8+
9+
#include "Arduino.h"
10+
#include <EMailSender.h>
11+
#include <WiFi.h>
12+
13+
uint8_t connection_state = 0;
14+
uint16_t reconnect_interval = 10000;
15+
16+
EMailSender emailSend("<YOUR-SMTP>", "<YOUR-SMTP-PASSWD>");
17+
18+
uint8_t WiFiConnect(const char* nSSID = nullptr, const char* nPassword = nullptr)
19+
{
20+
static uint16_t attempt = 0;
21+
Serial.print("Connecting to ");
22+
if(nSSID) {
23+
WiFi.begin(nSSID, nPassword);
24+
Serial.println(nSSID);
25+
}
26+
27+
uint8_t i = 0;
28+
while(WiFi.status()!= WL_CONNECTED && i++ < 50)
29+
{
30+
delay(200);
31+
Serial.print(".");
32+
}
33+
++attempt;
34+
Serial.println("");
35+
if(i == 51) {
36+
Serial.print("Connection: TIMEOUT on attempt: ");
37+
Serial.println(attempt);
38+
if(attempt % 2 == 0)
39+
Serial.println("Check if access point available or SSID and Password\r\n");
40+
return false;
41+
}
42+
Serial.println("Connection: ESTABLISHED");
43+
Serial.print("Got IP address: ");
44+
Serial.println(WiFi.localIP());
45+
return true;
46+
}
47+
48+
void Awaits()
49+
{
50+
uint32_t ts = millis();
51+
while(!connection_state)
52+
{
53+
delay(50);
54+
if(millis() > (ts + reconnect_interval) && !connection_state){
55+
connection_state = WiFiConnect();
56+
ts = millis();
57+
}
58+
}
59+
}
60+
61+
void setup()
62+
{
63+
Serial.begin(115200);
64+
const char* ssid = "<YOUR-SSID>";
65+
const char* password = "<YOUR-PASSWD>";
66+
67+
connection_state = WiFiConnect(ssid, password);
68+
if(!connection_state) // if not connected to WIFI
69+
Awaits(); // constantly trying to connect
70+
71+
EMailSender::EMailMessage message;
72+
message.subject = "Soggetto";
73+
message.message = "Ciao come stai<br>io bene.<br>www.mischianti.org";
74+
75+
// Send to 3 different email
76+
const char* arrayOfEmail[] = {"<FIRST>@gmail.com", "<SECOND>@yahoo.com", "<THIRD>@hotmail.com"};
77+
EMailSender::Response resp = emailSend.send(arrayOfEmail, 3, message);
78+
79+
// // Send to 3 different email, 2 in C and 1 in CC
80+
// const char* arrayOfEmail[] = {"<FIRST>@gmail.com", "<SECOND>@yahoo.com", "<THIRD>@hotmail.com"};
81+
// EMailSender::Response resp = emailSend.send(arrayOfEmail, 2, 1, message);
82+
//
83+
// // Send to 3 different email first to C second to CC and third to CCn
84+
// const char* arrayOfEmail[] = {"<FIRST>@gmail.com", "<SECOND>@yahoo.com", "<THIRD>@hotmail.com"};
85+
// EMailSender::Response resp = emailSend.send(arrayOfEmail, 3, message);
86+
87+
88+
Serial.println("Sending status: ");
89+
90+
Serial.println(resp.status);
91+
Serial.println(resp.code);
92+
Serial.println(resp.desc);
93+
}
94+
95+
void loop()
96+
{
97+
98+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=EMailSender
2-
version=2.1.0
2+
version=2.1.1
33
author=Renzo Mischianti <[email protected]>
44
maintainer=Renzo Mischianti <[email protected]>
55
sentence=EMail Arduino, esp8266 and esp32 Library.

0 commit comments

Comments
 (0)