Skip to content

Commit

Permalink
Merge pull request #27 from jeremydumais/version_1_1_7
Browse files Browse the repository at this point in the history
Version 1.1.7
  • Loading branch information
jeremydumais authored Jan 3, 2024
2 parents 010d788 + 5002b6c commit 2a9b14a
Show file tree
Hide file tree
Showing 32 changed files with 788 additions and 109 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ tags
Session.vim
.vimspector.json
.ccls-cache
.idea
cmake-build-debug
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

All notable changes to this project will be documented in this file

## [1.1.7]

### Added
- Added an option in the Credential class to indicate the preferred
authentication option. Support for the XOAUTH2 authentication has also been
added.This change has been made by rcosnita (https://github.com/rcosnita).
Many thanks!
- Added a new flag in the different SMTP client classes to indicate whether we
want to send emails in batch (getBatchMode/setBatchMode). In this mode the connection to an
SMTP server will only be made once when the first email is sent and will
remain open until the client instance is destroy.
- Added the authentication feature on the SMTPClient class.
- Added a new flag on the ForcedSecureSMTPClient and OpportunisticSecureSMTPClient
to indicate whether we accept self signed certificate
(getAcceptSelfSignedCert/setAcceptSelfSignedCert).


### Enhancement / Bug fixes
The following changes have been made by ino-josh (https://github.com/ino-josh).
Many thanks!

- Changed the default MAIL FROM format to fit the RFC.
- mCredential being a member of SMTPClientBase is now freed by it.
- Base64 encoding: added CRLF every so often to prevent rejection.
- Attachments: added mime types for audio files.
- Fix massive memory leak in createAttachmentsText of the SMTPClientBase class.


## [1.1.6]

### Added
Expand Down
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ if (WIN32)
ICON "${PATH_TO_APPLICATION_ICON}"
VERSION_MAJOR 1
VERSION_MINOR 1
VERSION_PATCH 6
VERSION_PATCH 7
VERSION_REVISION ${BUILD_REVISION}
)
endif()
Expand Down Expand Up @@ -158,6 +158,9 @@ else()
#For other compiler create the library as a static library
add_library(${PROJECT_NAME}
${PROJECT_SOURCE_FILES})
target_include_directories(${PROJECT_NAME} PUBLIC ${OPENSSL_INCLUDE_DIR})
get_filename_component(ssl_libdir ${OPENSSL_SSL_LIBRARY} DIRECTORY)
target_link_directories(${PROJECT_NAME} PUBLIC ${ssl_libdir})
target_link_libraries(${PROJECT_NAME} ssl crypto)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") #gcc
# https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
Expand All @@ -183,6 +186,7 @@ else()
"-Wuseless-cast" # (only in GCC >= 4.8) warn if you perform a cast to the same type
"-Wdouble-promotion" # (GCC >= 4.6, Clang >= 3.8) warn if float is implicit promoted to double
"-Wformat=2" # warn on security issues around functions that format output (ie printf)
"-fPIC"
)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
target_compile_options(${PROJECT_NAME}
Expand All @@ -193,6 +197,7 @@ else()
"-Wno-unused-lambda-capture" # FIX: It is necessary when building on MSVC
"-pedantic" # Issue all the warnings demanded by strict ISO C and ISO C++
"-pedantic-errors" # Like -pedantic, except that errors are produced rather than warnings http://stackoverflow.com/questions/30255294/how-to-hide-extra-output-from-pragma-message
"-fPIC"
)
endif()
endif()
Expand Down Expand Up @@ -266,3 +271,9 @@ ADD_CUSTOM_TARGET(uninstall
if(EXISTS ${PROJECT_PATH}/simpleclient AND IS_DIRECTORY ${PROJECT_PATH}/simpleclient)
add_subdirectory(${PROJECT_PATH}/simpleclient)
endif()

if(BUILD_EXAMPLE)
add_executable(emails-example src/cpp/example/send-mail.cpp)
target_include_directories(emails-example PUBLIC ${CMAKE_SOURCE_DIR}/src)
target_link_libraries(emails-example smtpclient ssl crypto stdc++)
endif()
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Jed# C++ SMTP Client Library

[![Build status](https://github.com/jeremydumais/CPP-SMTPClient-library/actions/workflows/cmake.yml/badge.svg)](https://github.com/jeremydumais/CPP-SMTPClient-library/actions/workflows/cmake.yml)
![Latest version](https://img.shields.io/badge/latest_version-1.1.6-brightgreen)
![Latest version](https://img.shields.io/badge/latest_version-1.1.7-brightgreen)
![Dependencies](https://img.shields.io/badge/dependencies-openssl-brightgreen)

## A simple SMTP client library built in C++ that support authentication and secure connections (Opportunistic SSL/TLS and Forced SSL encryption).
Expand Down Expand Up @@ -30,49 +30,49 @@ and [Linux](https://github.com/jeremydumais/CPP-SMTPClient-library/wiki/Build-th
<tr>
<td>

[v1.1.6 (x64)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.6/CPP-SMTPClient-Library.1.1.6.x64.zip)
[v1.1.7 (x64)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.7/CPP-SMTPClient-Library.1.1.7.x64.zip)

</td>
<td>

fc417d787a4533d3b6c99c1b5e852b5b
fb041c2e377d6e399853b1fd4f0f2396

</td>
</tr>
<tr>
<td>

[v1.1.6 (x86)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.6/CPP-SMTPClient-Library.1.1.6.x86.zip)
[v1.1.7 (x86)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.7/CPP-SMTPClient-Library.1.1.7.x86.zip)

</td>
<td>

ffdd7f2adbf92b9a3dfd8bbf97c83008
bb98d97a03451ff579226b0361c2a7ce

</td>
</tr>

<tr>
<td>

[v1.1.5 (x64)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.5/CPP-SMTPClient-Library.1.1.5.x64.zip)
[v1.1.6 (x64)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.6/CPP-SMTPClient-Library.1.1.6.x64.zip)

</td>
<td>

b28a2fe6c85ef485b4175c60b6c8c018
fc417d787a4533d3b6c99c1b5e852b5b

</td>
</tr>
<tr>
<td>

[v1.1.5 (x86)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.5/CPP-SMTPClient-Library.1.1.5.x86.zip)
[v1.1.6 (x86)](https://github.com/jeremydumais/CPP-SMTPClient-library/releases/download/v1.1.6/CPP-SMTPClient-Library.1.1.6.x86.zip)

</td>
<td>

d7bce46ec3cfd49bfb342d82a3905e5f
ffdd7f2adbf92b9a3dfd8bbf97c83008

</td>
</tr>
Expand All @@ -85,6 +85,20 @@ for previous versions.

## 📰 What's new

- Version 1.1.7:
- Added support for the XOAUTH2 authentication method.
This change has been made by rcosnita (https://github.com/rcosnita).
Many thanks!
- Added a new flag in the different SMTP client classes to indicate whether we
want to send emails in batch (getBatchMode/setBatchMode). In this mode the connection to an
SMTP server will only be made once when the first email is sent and will
remain open until the client instance is destroy.
- Added the authentication feature on the SMTPClient class.
- Added a new flag on the ForcedSecureSMTPClient and OpportunisticSecureSMTPClient
to indicate whether we accept self signed certificate
(getAcceptSelfSignedCert/setAcceptSelfSignedCert).
- Many more enhancements provided by ino-josh (https://github.com/ino-josh).
Many thanks!
- Version 1.1.6: Added support in the attachment class for Content-ID. It will
be really useful to uniquely identify and reference resources to embed in the
message.
Expand Down Expand Up @@ -302,6 +316,16 @@ c: QUIT\r\n
Operation completed!
```

## 🗝 Complete XOAUTH2 authentication example

We also provide a fully working example. See [send-mail.cpp](./src/cpp/example/send-mail.cpp).
Make sure you replace the username and password (access token) placeholders with correct values.

The example uses GMail smtp server with [XOauth2 authentication mechanism](https://developers.google.com/gmail/imap/xoauth2-protocol).

For testing purposes, you can obtain an OAuth access token for you gmail account by using the [OAuth 2.0 Playground](https://developers.google.com/oauthplayground/).
You can follow this procedure for more details: [Obtaining an access token for your gmail account](https://github.com/jeremydumais/CPP-SMTPClient-library/wiki/Obtain-An-Access-Token-Gmail)

## 🧪 Unit tests
[How to run the unit tests](https://github.com/jeremydumais/CPP-SMTPClient-library/wiki/Run-the-unit-tests)

Expand Down
18 changes: 16 additions & 2 deletions src/attachment.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "attachment.h"
#include <algorithm>
#include <cstdint>
#include <ios>
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
#include "stringutils.h"

Expand Down Expand Up @@ -224,6 +222,22 @@ const char *Attachment::getMimeType() const {
if (extension == "WEBM") {
return "video/webm";
}
// Audio
if (extension == "WAV") {
return "audio/wav";
}
if (extension == "MP3") {
return "audio/mpeg";
}
if (extension == "OGA") {
return "audio/ogg";
}
if (extension == "OPUS") {
return "audio/opus";
}
if (extension == "AAC") {
return "audio/aac";
}
// Archives
if (extension == "ZIP") {
return "application/zip";
Expand Down
8 changes: 8 additions & 0 deletions src/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static inline bool is_base64(unsigned char c) {
std::string Base64::Encode(unsigned char const *bytes_to_encode, size_t in_len) {
std::string ret;
int i = 0;
size_t out_len = 0;
unsigned char char_array_3[3];
unsigned char char_array_4[4];

Expand All @@ -57,6 +58,13 @@ std::string Base64::Encode(unsigned char const *bytes_to_encode, size_t in_len)
for (i = 0; (i < 4); i++)
ret += base64_chars[char_array_4[i]];
i = 0;

// Some servers reject any email with a line that is "too long" (hMailServer does this, for example).
// Since attachments can be quite large, we break up the output with \r\n to avoid this.
out_len += 4;
if (out_len % (64 * 1024) == 0) {
ret += "\r\n";
}
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/cpp/credential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Credential::Credential(const std::string &pUsername, const std::string &pPasswor
: jed_utils::Credential(pUsername.c_str(), pPassword.c_str()) {
}

Credential::Credential(const std::string &pUsername, const std::string &pPassword,
RecommendedAuthenticationMethod authOption)
: Credential(pUsername, pPassword) {
jed_utils::Credential::setRecommendedAuthOption(authOption);
}

std::string Credential::getUsername() const {
return jed_utils::Credential::getUsername();
}
Expand All @@ -14,10 +20,20 @@ std::string Credential::getPassword() const {
return jed_utils::Credential::getPassword();
}

auto Credential::getRecommendedAuthOption() const
-> RecommendedAuthenticationMethod {
return jed_utils::Credential::getRecommendedAuthOption();
}

void Credential::setUsername(const std::string &pUsername) {
jed_utils::Credential::setUsername(pUsername.c_str());
}

void Credential::setPassword(const std::string &pPassword) {
jed_utils::Credential::setPassword(pPassword.c_str());
}

void Credential::setRecommendedAuthOption(
RecommendedAuthenticationMethod authOption) {
jed_utils::Credential::setRecommendedAuthOption(authOption);
}
20 changes: 20 additions & 0 deletions src/cpp/credential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class CPP_CREDENTIAL_API Credential : private jed_utils::Credential {
*/
Credential(const std::string &pUsername, const std::string &pPassword);

/**
* @brief Construct a new Credential.
* @param pUsername The user name.
* @param pPassword The password.
*/
Credential(const std::string &pUsername, const std::string &pPassword,
RecommendedAuthenticationMethod authOption);

/** The destructor og Credential */
~Credential() override = default;

Expand All @@ -49,6 +57,10 @@ class CPP_CREDENTIAL_API Credential : private jed_utils::Credential {
/** Return the password. */
std::string getPassword() const;

/** Returns the recommended authentication option
* currently set for the credentials. */
RecommendedAuthenticationMethod getRecommendedAuthOption() const;

/**
* @brief Set the user name.
* @param pUsername A char array pointer of the user name.
Expand All @@ -60,6 +72,14 @@ class CPP_CREDENTIAL_API Credential : private jed_utils::Credential {
* @param pPassword A char array pointer of the password.
*/
void setPassword(const std::string &pPassword);

/**
* @brief Changes the recommended authentication method for this set
* of credentials.
* @param authOption The recommended authentication option that we should use
* while authenticating the client using the current set of credentials.
*/
void setRecommendedAuthOption(RecommendedAuthenticationMethod authOption);
};
} // namespace cpp
} // namespace jed_utils
Expand Down
Loading

0 comments on commit 2a9b14a

Please sign in to comment.