Skip to content

[Windows] Build the CPP SMTPClient library

Jeremy Dumais edited this page Apr 19, 2025 · 1 revision

Build the CPP-SMTPClient-library on Windows

1 - Getting OpenSSL dependency

To get OpenSSL in order to build the CPP-SMTPClient-Library you can use one of the following way (Chocolatey or OpenSSL Downloaded Binary).

Chocolatey

You can install Chocolatey on your system following the guide here

Once installed, you need to start a command prompt as an admin and type the following command:

choco install openssl

If you want the 32 bits version use the following command:

choco install --forceX86 openssl

The resulting files will then be in C:\Program Files\OpenSSL-Win64 or C:\Program Files (x86)\OpenSSL-Win32 depending on the version you took.

I strongly suggest to create an environment variable OPENSSL_ROOT_DIR that point to your installation folder. (Ex: C:\Program Files\OpenSSL-Win64)

It is recommended to use the command RefreshEnv to make sure your environment variables are refreshed.

OpenSSL Binary Distributions for Microsoft Windows

You can download one of the prebuilt binary here.

Once downloaded and extracted on your hard drive, I strongly suggest to create an environment variable OPENSSL_ROOT_DIR that point to your installation folder. (Ex: C:\openssl\x64)

It is recommended to close and reopen your Windows session to make sure that your environment variables are refreshed.

2 - Getting the CPP-SMTP-Library source code

Navigate to the folder where you want the solution to be and then enter the following command:

git clone https://github.com/jeremydumais/CPP-SMTPClient-library.git

3 - Preparing the build folder

When building CPP-SMTPClient-library as a standalone project, the typical workflow starts with:

cd CPP-SMTPClient-library
mkdir build
cd build

4 - Configuration and generation

The next step is to configure and generate project files. Enter one of the following command depending on the version and the mode you want:

Release mode

64 bits (x64)

cmake ..

32 bits (x86)

cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -T host=x86 ..

Debug mode

64 bits (x64)

cmake -DCMAKE_BUILD_TYPE=Debug ..

32 bits (x86)

cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Debug -T host=x86 ..

Static library

By default the library is build as dynamic, meaning the library will be stored in a separate file (.dll file extension).

If you want to build the library as static you need to turn off the CMake flag BUILD_SHARED_LIBS.

cmake -DBUILD_SHARED_LIBS=OFF ..

Including unit tests

The library unit tests will not be built by default. To include them just add the BUILD_TESTING=ON to the configure command.

cmake -DBUILD_TESTING=ON ..

Troubleshooting OpenSSL folders and library files

During the configuration and generation phase you will see if CMake was able to find OpenSSL or not.

See below an example of resulting configuration and generation. The OpenSSL important lines are in bold.

-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.26.28806.0
-- The CXX compiler identification is MSVC 19.26.28806.0
...
-- Found OpenSSL: optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib (found version "1.1.1s")
-- WARNING: building release version!
-- No OPENSSL_ROOT_DIR variable provided so searching for the OPENSSL_ROOT_DIR environment variable...
-- Found OPENSSL_ROOT_DIR=C:\Program Files\OpenSSL-Win64 as an environment variable.
-- Will use OpenSSL include directory C:\Program Files\OpenSSL-Win64/include
-- Will use OpenSSL lib directory C:\Program Files\OpenSSL-Win64/lib}
-- Will use OpenSSL libraries files optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libssl64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libssl64MDd.lib

-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jed/Source/Repos/CPP-SMTPClient-library/build

If for some reasons OpenSSL was not found correctly, you can provide your folders and library files via the following CMake variables:

  • OPENSSL_ROOT_DIR
  • OPENSSL_INCLUDE_DIRECTORY
  • OPENSSL_LIBRARY_DIRECTORY
  • OPENSSL_CRYPTO_LIBRARY
  • OPENSSL_SSL_LIBRARY

Ex:

cmake -DOPENSSL_ROOT_DIR=C:\openssl\x64 -DOPENSSL_INCLUDE_DIRECTORY=C:\openssl\x64\include -DOPENSSL_LIBRARY_DIRECTORY=C:\openssl\x64\lib -DOPENSSL_CRYPTO_LIBRARY=crypto -DOPENSSL_SSL_LIBRARY=ssl ..

5 - Building the library

Release mode

cmake --build . --config Release

Debug mode

cmake --build . --config Debug

The resulting library smtpclient.dll should be created in the folder build\bin\Debug or build\bin\Release depending on the build mode you have chosen.

You can also build the project using Visual Studio, just click File -> Open -> Folder... and the select the folder where you have downloaded CPP-SMTPClient-library. You can then build the project using Visual Studio.

6 - Installing the library

From the build folder, in an administrator command prompt, run the following command:

cmake --install . --config Release

The next step is to consume the library from your own solution. Follow this guide to for more information: How to consume the CPP-SMTP-Library in your application

If you want to uninstall the library, simply run the following command:

cmake -P cmake_uninstall.cmake
Clone this wiki locally