1. Products
  2.   Email
  3.   C++
  4.   SimpleMail
 
  

Send/Receive Emails with HTML Content via Free C++ Library

Open Source C++ Email Library for Emails Sending & Receiving with Support for Modern Authentication, MIME Formatting, Attachments, SMTP, HTML Content, and SSL/TLS Encryption.

What is SimpleMail?

In the world of modern C++ development, handling email functionality efficiently and securely is crucial for a wide variety of applications—from notification systems to user verifications. While many high-level languages offer rich libraries for SMTP email handling, C++ has historically lacked a truly lightweight and simple solution. SimpleMail is a C++ library built atop the QtCore and QtNetwork modules. It provides a simple interface for sending MIME-compliant email messages via SMTP servers, including support for SSL/TLS encryption, SMTP authentication, Plain text and HTML message content, File attachments, multiple recipients (To, Cc, Bcc) and so on. Devices that monitor conditions (e.g., temperature sensors or smart home gateways) can use SimpleMail to alert users in case of anomalies.

SimpleMail is a minimalist yet powerful library that lets C++ applications send emails with attachments, HTML content, and more via SMTP. Maintained on GitHub, SimpleMail is a Qt-based SMTP client library designed for ease of use, flexibility, and robustness. Whether you're building a desktop app or a server-side daemon in C++, the library provides a clean and practical interface for sending emails. If you’re using frameworks like Cutelyst or Wt, SimpleMail is a natural fit for sending user-related notifications or transactional emails. SimpleMail is a breath of fresh air for C++ developers looking to integrate email capabilities directly into their applications. With a small footprint, strong support for modern email protocols, and seamless integration with the Qt framework, it offers exactly what many C++ developers have been waiting for.

Previous Next

Getting Started with SimpleMail

The recommend way to install SimpleMail is using GitHub. Please use the following command for a smooth installation.

install SimpleMail via GitHub

git clone https://github.com/cutelyst/simple-mail.git

Create HTML Email via C++ API

The open source SimpleMail library supports sending emails with both plain text and HTML content, allowing for richer email formatting. You can specify an HTML body for visually appealing emails while also providing a plain text alternative for email clients that don't support HTML or for users who prefer it. The library makes it easy to send formatted emails with images or custom styles, because it allows HTML content in your message. The following code snippets shows, how software developers can send an HTML Email with Inline Images.

How to Send an HTML Email with Inline Images via C++ API?

#include 

int main() {
    SimpleMail::Mailer mailer("smtp.gmail.com", 587);
    mailer.setUsername("your-email@gmail.com");
    mailer.setPassword("your-password");

    SimpleMail::Mail mail;
    mail.setSender("your-email@gmail.com");
    mail.addTo("recipient@example.com");
    mail.setSubject("HTML Email with Image");

    // HTML content with an embedded image
    mail.setBody(
        "

Welcome!

" "

This is an HTML email with an inline image:

" "Company Logo", SimpleMail::Mail::BodyType::Html ); // Attach an image and reference it in HTML using CID mail.addAttachment("logo.png", "logo", "image/png"); if (mailer.sendMail(mail)) { std::cout << "HTML email sent successfully!" << std::endl; } else { std::cerr << "Error: " << mailer.lastError() << std::endl; } return 0; }

SMTP Support with Authentication

The open source SimpleMail library has provided complete support for SMTP authentication inside C++ applications. The library supports both plain and login authentication methods. This ensures compatibility with most SMTP servers, including Gmail, Outlook, and custom servers. Here is a useful code snippet that shows how easily C++ developers can configure SMTP settings, including STARTTLS over port 587.

How to Configure SMTP Settings inside C++ Apps?

SimpleMail::Sender sender;
sender.setHost("smtp.example.com");
sender.setPort(587);
sender.setConnectionType(SimpleMail::Sender::TlsConnection);
sender.setUser("your-email@example.com");
sender.setPassword("your-password");

Send Emails with Attachments via C++

Adding attachments to your emails is a common requirement, and SimpleMail handles this seamlessly. The library makes it easy to generate new emails and attach files to these messages with just a couple of lines. It takes care of encoding the attachment and setting the appropriate MIME types. Developers can specify the file path and optionally a custom filename for the attachment. The following example shows how software developers can send an Email with File Attachments via C++ API.

How to Send an Email Message with File Attachments via C++ Library?

#include 

int main() {
    SimpleMail::Mailer mailer("smtp.example.com", 465);
    mailer.setUsername("user@example.com");
    mailer.setPassword("password");
    mailer.setSsl(true); // Enable SSL for secure connection

    SimpleMail::Mail mail;
    mail.setSender("user@example.com");
    mail.addTo("client@example.com");
    mail.setSubject("Invoice Attached");
    mail.setBody("Please find the attached invoice.");

    // Attach a PDF file
    mail.addAttachment("/path/to/invoice.pdf", "invoice.pdf", "application/pdf");

    if (mailer.sendMail(mail)) {
        std::cout << "Email with attachment sent!" << std::endl;
    } else {
        std::cerr << "Error: " << mailer.lastError() << std::endl;
    }

    return 0;
}

Better Security with SSL/TLS Support

Security is paramount when dealing with email. The SimpleMail library supports secure connections to SMTP servers using SSL (Secure Sockets Layer) and TLS (Transport Layer Security). When configuring the SmtpServer, you can specify the ConnectionType as Ssl or Tls to ensure that the communication with the mail server is encrypted. This protects the email content and authentication credentials from being intercepted.