-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IMAP sendCustomData function and add IMAP append message example.
- Loading branch information
Showing
8 changed files
with
333 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
examples/IMAP/Custom_Command/Append_Message/Append_Message.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/** | ||
* This example shows how to append new message to mailbox using the custom IMAP command. | ||
* | ||
* Email: suwatchai@outlook.com | ||
* | ||
* Github: https://github.com/mobizt/ESP-Mail-Client | ||
* | ||
* Copyright (c) 2022 mobizt | ||
* | ||
*/ | ||
|
||
/** 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> | ||
#else | ||
|
||
// Other Client defined here | ||
// To use custom Client, define ENABLE_CUSTOM_CLIENT in src/ESP_Mail_FS.h. | ||
// See the example Custom_Client.ino for how to use. | ||
|
||
#endif | ||
|
||
#include <ESP_Mail_Client.h> | ||
|
||
// To use only IMAP functions, you can exclude the SMTP from compilation, see ESP_Mail_FS.h. | ||
|
||
#define WIFI_SSID "<ssid>" | ||
#define WIFI_PASSWORD "<password>" | ||
|
||
/** For Gmail, IMAP option should be enabled. https://support.google.com/mail/answer/7126229?hl=en | ||
* and also https://accounts.google.com/b/0/DisplayUnlockCaptcha | ||
* | ||
* Some Gmail user still not able to sign in using account password even above options were set up, | ||
* for this case, use "App Password" to sign in instead. | ||
* About Gmail "App Password", go to https://support.google.com/accounts/answer/185833?hl=en | ||
* | ||
* For Yahoo mail, log in to your yahoo mail in web browser and generate app password by go to | ||
* https://login.yahoo.com/account/security/app-passwords/add/confirm?src=noSrc | ||
* | ||
* To use Gmai and Yahoo's App Password to sign in, define the AUTHOR_PASSWORD with your App Password | ||
* and AUTHOR_EMAIL with your account email. | ||
*/ | ||
|
||
/* The imap host name e.g. imap.gmail.com for GMail or outlook.office365.com for Outlook */ | ||
#define IMAP_HOST "<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 "<email>" | ||
#define AUTHOR_PASSWORD "<password>" | ||
|
||
/* The IMAP Session object used for Email reading */ | ||
IMAPSession imap; | ||
|
||
void customCommandCallback(IMAP_Response res) | ||
{ | ||
// The server responses will included tagged and/or untagged data. | ||
|
||
// Tagged data is the status which begins with command identifier (tag) i.e. "A01" in this case. | ||
// Tagged status responses included OK, NO, BAD, PREAUTH and BYE. | ||
|
||
// Untagged data is the information or result of the request which begins with * | ||
|
||
// When you send multiple commands with different tag simultaneously, | ||
// tag will be used as command identifier. | ||
|
||
Serial.print("> C: TAG "); | ||
Serial.println(res.tag.c_str()); | ||
Serial.print("< S: "); | ||
Serial.println(res.text.c_str()); | ||
|
||
if (res.completed) | ||
{ | ||
Serial.print("> C: Response finished with status "); | ||
Serial.println(res.status.c_str()); | ||
Serial.println(); | ||
} | ||
} | ||
|
||
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(); | ||
|
||
/* Declare the session config data */ | ||
ESP_Mail_Session session; | ||
|
||
/* Set the session config */ | ||
session.server.host_name = IMAP_HOST; | ||
session.server.port = IMAP_PORT; | ||
|
||
/* Connect to server with the session and config */ | ||
if (!imap.customConnect(&session, customCommandCallback, F("A01") /* tag */)) | ||
return; | ||
|
||
String cmd = F("LOGIN "); | ||
cmd += AUTHOR_EMAIL; | ||
cmd += F(" "); | ||
cmd += AUTHOR_PASSWORD; | ||
|
||
// You can also assign tag to the begining of the command e.g. "A01 FETCH 1 UID" | ||
// Do not assign tag to command when you assign tag to the last parameter of function. | ||
|
||
imap.sendCustomCommand(cmd, customCommandCallback, F("A02") /* tag */); | ||
|
||
imap.sendCustomCommand(F("SELECT \"INBOX\""), customCommandCallback, F("A03") /* tag */); | ||
|
||
imap.sendCustomCommand(F("LIST \"\" *"), customCommandCallback, F("A04") /* tag */); | ||
|
||
String appendMsg = "Date: Thu, 16 Jun 2022 12:30:25 -0800 (PST)\r\n"; | ||
|
||
appendMsg += "From: Jack <jack@host.com>\r\n"; | ||
|
||
appendMsg += "Subject: Greeting from ESP Mail\r\n"; | ||
|
||
appendMsg += "To: joe@host.com\r\n"; | ||
|
||
appendMsg += "Message-Id: <jack@host.com>\r\n"; | ||
|
||
appendMsg += "MIME-Version: 1.0\r\n"; | ||
|
||
appendMsg += "Content-Type: text/plain; charset=\"us-ascii\"\r\n"; | ||
|
||
appendMsg += "Content-transfer-encoding: 7bit\r\n"; | ||
|
||
appendMsg += "\r\n"; | ||
|
||
appendMsg += "Hello Joe, this is the append message\r\n"; | ||
|
||
String appendMsgCmd = "APPEND INBOX {" + String(appendMsg.length()) + "}"; | ||
|
||
imap.sendCustomCommand(appendMsgCmd, customCommandCallback, F("A05") /* tag */); | ||
|
||
imap.sendCustomData(appendMsg, true /* flag states the last data to send */); | ||
} | ||
|
||
void loop() | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name=ESP Mail Client | ||
|
||
version=2.4.2 | ||
version=2.4.3 | ||
|
||
author=Mobizt | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ | |
|
||
#ifndef ESP_MAIL_VERSION | ||
|
||
#define ESP_MAIL_VERSION "2.4.2" | ||
#define ESP_MAIL_VERSION "2.4.3" | ||
|
||
#endif |
Oops, something went wrong.