Skip to content

Commit

Permalink
Fix SMTP XOAUTH2 authentication issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 20, 2023
1 parent 85276c1 commit 820f8c9
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 22 deletions.
2 changes: 0 additions & 2 deletions examples/SMTP/Send_Access_Token/Send_Access_Token.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
* To test this using GMail, get the OAuth2.0 access token from this web site
* https://developers.google.com/oauthplayground/
*
* You can use the ESP Signer library to generate OAuth2.0 access token
* The library is available here https://github.com/mobizt/ESP-Signer
*
* 1. Select the following scope (in Step 1) from Gmail API V1
* https://mail.google.com/
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP Mail Client",
"version": "3.2.1",
"version": "3.2.2",
"keywords": "communication, email, imap, smtp, esp32, esp8266, samd, arduino",
"description": "Arduino E-Mail Client Library to send, read and get incoming email notification for ESP32, ESP8266 and SAMD21 devices. The library also supported other Arduino Devices using Clients interfaces e.g. WiFiClient, EthernetClient, and GSMClient.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=ESP Mail Client

version=3.2.1
version=3.2.2

author=Mobizt

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_CLIENT_CPP

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#define ESP_MAIL_CLIENT_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

/**
* Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module
*
* Created June 17, 2023
* Created June 20, 2023
*
* This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers.
*
Expand Down
4 changes: 2 additions & 2 deletions src/ESP_Mail_Client_Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#ifndef ESP_MAIL_VERSION

#define ESP_MAIL_VERSION "3.2.1"
#define ESP_MAIL_VERSION_NUM 30201
#define ESP_MAIL_VERSION "3.2.2"
#define ESP_MAIL_VERSION_NUM 30202

/* The inconsistent file version checking to prevent mixed versions compilation. */
#define VALID_VERSION_CHECK(ver) (ver == ESP_MAIL_VERSION_NUM)
Expand Down
6 changes: 4 additions & 2 deletions src/ESP_Mail_Const.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Created April 16, 2022
// Created July 20, 2023

#pragma once

#ifndef ESP_MAIL_CONST_H
#define ESP_MAIL_CONST_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down Expand Up @@ -1109,6 +1109,8 @@ struct esp_mail_smtp_auth_tokens

// The smtp auth capability with leading space.
static esp_mail_smtp_auth_tokens smtp_auth_cap_pre_tokens(true);
// The smtp auth capability with trailing space.
static esp_mail_smtp_auth_tokens smtp_auth_cap_post_tokens(false);

struct esp_mail_smtp_send_capability_t
{
Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define ESP_MAIL_ERROR_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ESP_MAIL_CONFIG_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_IMAP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#define ESP_MAIL_IMAP_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/ESP_Mail_Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define ESP_MAIL_PRINT_H_

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
12 changes: 8 additions & 4 deletions src/ESP_Mail_SMTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#define ESP_MAIL_SMTP_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

/**
* Mail Client Arduino Library for Espressif's ESP32 and ESP8266, Raspberry Pi RP2040 Pico, and SAMD21 with u-blox NINA-W102 WiFi/Bluetooth module
*
* Created July 14, 2023
* Created July 20, 2023
*
* This library allows Espressif's ESP32, ESP8266, SAMD and RP2040 Pico devices to send and read Email through the SMTP and IMAP servers.
*
Expand Down Expand Up @@ -195,7 +195,7 @@ bool ESP_Mail_Client::smtpAuth(SMTPSession *smtp, bool &ssl)
return handleSMTPError(smtp, SMTP_STATUS_SERVER_OAUTH2_LOGIN_DISABLED, false);

MB_String cmd = smtp_cmd_post_tokens[esp_mail_smtp_command_auth];
cmd += smtp_auth_cap_pre_tokens[esp_mail_auth_capability_xoauth2];
cmd += smtp_auth_cap_post_tokens[esp_mail_auth_capability_xoauth2];

if (smtpSend(smtp, cmd.c_str(), false) == ESP_MAIL_CLIENT_TRANSFER_DATA_FAILED)
return false;
Expand Down Expand Up @@ -2753,7 +2753,7 @@ bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_comman
int readLen = 0;
long dataTime = millis();
int chunkBufSize = 0;
MB_String s, r;
MB_String s, r, err;
int chunkIndex = 0;
int count = 0;
bool completedResponse = false;
Expand Down Expand Up @@ -2908,7 +2908,10 @@ bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_comman
size_t olen = 0;
char *decoded = (char *)decodeBase64((const unsigned char *)status.text.c_str(), status.text.length(), &olen);
if (decoded && olen > 0)
{
s.append(decoded, olen);
err = decoded;
}

// release memory
freeMem(&decoded);
Expand All @@ -2934,6 +2937,7 @@ bool ESP_Mail_Client::handleSMTPResponse(SMTPSession *smtp, esp_mail_smtp_comman
{
if (isOAuthError(response, readLen, chunkIndex, 4))
{
smtp->_smtpStatus.text= err;
smtp->_smtpStatus.errorCode = SMTP_STATUS_XOAUTH2_AUTH_FAILED;
ret = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/extras/MB_Time.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MB_Time_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/extras/RFC2047.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define RFC2047_CPP

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/extras/RFC2047.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define RFC2047_H

#include "ESP_Mail_Client_Version.h"
#if !VALID_VERSION_CHECK(30201)
#if !VALID_VERSION_CHECK(30202)
#error "Mixed versions compilation."
#endif

Expand Down

0 comments on commit 820f8c9

Please sign in to comment.