Skip to content

Commit

Permalink
Add support IMAP mailbox changes notification, add IMAP functions and…
Browse files Browse the repository at this point in the history
… update examples.
  • Loading branch information
mobizt committed Sep 13, 2021
1 parent 422c016 commit 145ac61
Show file tree
Hide file tree
Showing 33 changed files with 1,295 additions and 63 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/compile_examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
matrix:
example:
- "examples/IMAP/Copy_Messages/Copy_Messsages.ino"
- "examples/IMAP/Custom_Command/Custom_Command.ino"
- "examples/IMAP/Delete_Messages/Delete_Messsages.ino"
- "examples/IMAP/Mailbox_Changes_Notification/Mailbox_Changes_Notification.ino"
- "examples/IMAP/Read_Email_Access_Token/Read_Email_Access_Token.ino"
- "examples/IMAP/Read_Single_Email/Read_Single_Email.ino"
- "examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino"
Expand Down Expand Up @@ -82,7 +84,9 @@ jobs:
matrix:
example:
- "examples/IMAP/Copy_Messages/Copy_Messsages.ino"
- "examples/IMAP/Custom_Command/Custom_Command.ino"
- "examples/IMAP/Delete_Messages/Delete_Messsages.ino"
- "examples/IMAP/Mailbox_Changes_Notification/Mailbox_Changes_Notification.ino"
- "examples/IMAP/Read_Email_Access_Token/Read_Email_Access_Token.ino"
- "examples/IMAP/Read_Single_Email/Read_Single_Email.ino"
- "examples/IMAP/Read_Single_Email_Loop/Read_Single_Email_Loop.ino"
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Mail Client Arduino Library v1.4.2
# Mail Client Arduino Library v1.5.0


[![Join the chat at https://gitter.im/mobizt/ESP_Mail_Client](https://badges.gitter.im/mobizt/ESP_Mail_Client.svg)](https://gitter.im/mobizt/ESP_Mail_Client?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down Expand Up @@ -33,14 +33,15 @@ Copyright (c) 2021 K. Suwatchai (Mobizt).
* Support TCP session reusage.
* Support PLAIN, LOGIN and XOAUTH2 authentication mechanisms.
* Support secured (with SSL and TLS or upgrade via STARTTLS) and non-secure ports.
* Support mailbox selection for Email reading and searching.
* Support mailbox selection for Email reading and searching (IMAP).
* Support mailbox changes notification (IMAP).
* Support the content encodings e.g. quoted-printable and base64.
* Support the content decodings e.g. base64, UTF-8, UTF-7, quoted-printable, ISO-8859-1 (latin1) and ISO-8859-11 (Thai).
* Support embedded contents e.g. inline images, attachments, parallel media attachments and RFC822 message.
* Support full debuging.
* Support flash memory (ESP32 and ESP8266), SD and SD_MMC (ESP32) for file storages which can be changed in [**ESP_Mail_FS.h**](/src/ESP_Mail_FS.h).
* Support Ethernet (ESP32 using LAN8720, TLK110 and IP101 Ethernet modules, and ESP8266 (Arduino Core SDK v3.x.x and later) using ENC28J60, W5100 and W5500 Ethernet modules).
* Customizable operating configurations (see the examples for the usages)
* Customizable configurations (see the examples for the usages)



Expand Down Expand Up @@ -148,7 +149,7 @@ The flash (upload) result shows in the command prompt window will look similar t
If the custom built WiFiNINA firmware was installed, the debug message will show the library version with WiFiNINA firmware version which followed by built number (+21060).

```
> C: ESP Mail Client v1.4.2, Fw v1.4.5+21060
> C: ESP Mail Client v1.5.0, Fw v1.4.5+21060
```

## Library Instalation
Expand Down
2 changes: 2 additions & 0 deletions examples/IMAP/Copy_Messages/Copy_Messsages.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void setup()
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*
* Debug port can be changed via ESP_Mail_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
*/
imap.debug(1);

Expand Down
149 changes: 149 additions & 0 deletions examples/IMAP/Custom_Command/Custom_Command.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/**
* This example showed how to send custom IMAP command and get the server response.
*
* Email: suwatchai@outlook.com
*
* Github: https://github.com/mobizt/ESP-Mail-Client
*
* Copyright (c) 2021 mobizt
*
*/

/** To receive Email using Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en
* and also https://accounts.google.com/b/0/DisplayUnlockCaptcha
*
*/

/** For ESP8266, with BearSSL WiFi Client
* The memory reserved for completed valid SSL response from IMAP is 16 kbytes which
* may cause your device out of memory reset in case the memory
* allocation error.
*/

#include <Arduino.h>
#if defined(ESP32)
#include <WiFi.h>
#elif defined(ESP8266)
#include <ESP8266WiFi.h>
#endif
#include <ESP_Mail_Client.h>

#define WIFI_SSID "################"
#define WIFI_PASSWORD "################"

/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */
#define IMAP_HOST "################"

/** The imap port e.g.
* 143 or esp_mail_imap_port_143
* 993 or esp_mail_imap_port_993
*/
#define IMAP_PORT 993

/* The log in credentials */
#define AUTHOR_EMAIL "################"
#define AUTHOR_PASSWORD "################"

/* Print the list of mailbox folders */
void printAllMailboxesInfo(IMAPSession &imap);

/* Print the selected folder info */
void printSelectedMailboxInfo(IMAPSession &imap);

/* The IMAP Session object used for Email reading */
IMAPSession imap;

void customCommandCallback(const char *res)
{
Serial.print("< S: ");
Serial.println(res);
}

void setup()
{

Serial.begin(115200);

#if defined(ARDUINO_ARCH_SAMD)
while (!Serial)
;
Serial.println();
Serial.println("**** Custom built WiFiNINA firmware need to be installed.****\nTo install firmware, read the instruction here, https://github.com/mobizt/ESP-Mail-Client#install-custom-built-wifinina-firmware");

#endif

Serial.println();

Serial.print("Connecting to AP");

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(200);
}

Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println();

/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*
* Debug port can be changed via ESP_Mail_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
*/
imap.debug(1);

/* Declare the session config data */
ESP_Mail_Session session;

/* Set the session config */
session.server.host_name = IMAP_HOST;
session.server.port = IMAP_PORT;
session.login.email = AUTHOR_EMAIL;
session.login.password = AUTHOR_PASSWORD;

/* Setup the configuration for searching or fetching operation and its result */
IMAP_Config config;

/* Connect to server with the session and config */
if (!imap.connect(&session, &config))
return;

/* {Optional] */
printAllMailboxesInfo(imap);

/* Open or select the mailbox folder to read or search the message */
if (!imap.selectFolder("INBOX"))
return;

/* Send custom command to fetch message no.1 for UID */
Serial.println("Send custom command to fetch message no.1 for UID");
Serial.println("---------------------");

imap.sendCustomCommand("A01 FETCH 1 UID", customCommandCallback);
}

void loop()
{
}

void printAllMailboxesInfo(IMAPSession &imap)
{
/* Declare the folder collection class to get the list of mailbox folders */
FoldersCollection folders;

/* Get the mailbox folders */
if (imap.getFolders(folders))
{
for (size_t i = 0; i < folders.size(); i++)
{
/* Iterate each folder info using the folder info item data */
FolderInfo folderInfo = folders.info(i);
ESP_MAIL_PRINTF("%s%s%s", i == 0 ? "\nAvailable folders: " : ", ", folderInfo.name, i == folders.size() - 1 ? "\n" : "");
}
}
}
2 changes: 2 additions & 0 deletions examples/IMAP/Delete_Messages/Delete_Messsages.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ void setup()
/** Enable the debug via Serial port
* none debug or 0
* basic debug or 1
*
* Debug port can be changed via ESP_Mail_DEFAULT_DEBUG_PORT in ESP_Mail_FS.h
*/
imap.debug(1);

Expand Down
Loading

0 comments on commit 145ac61

Please sign in to comment.