Create Outlook Emails (MSG, EML, EMLX) using C++

Create Outlook Emails in C++

Email Automation is quite popular these days for generating and sending emails automatically from within the web or desktop applications. It is being used for sending important notifications, documents, newsletters, and various kinds of other messages. In order to develop an automated email system, Aspose facilitates the developers with its email API – Aspose.Email. Today, I’m going to pick up the C++ variant of Aspose.Email and show you how to create Outlook emails using C++.

C++ Email Library to Create Outlook Emails

Aspose.Email for C++ is a native C++ library that lets you create and send emails of MS Outlook and other popular email formats. It also allows you to manipulate Outlook objects such as calendars, tasks, contacts, etc. and convert the existing email files to other formats. You can download the complete library package from here or install it within your C++ application using NuGet.

Create an Outlook Email using C++

First of all, let’s check out how to create a simple email message and save it in an email format such as MSG, EML, and EMLX. The following are the steps to create an email message using Aspose.Email for C++.

  • Create an instance of MailMessage class.
  • Set the message’s properties such as To, From, and Body.
  • Save the email message using MailMessage->Save() method.

The following code sample shows how to create an Outlook message in a particular email format using C++.

Create an Outlook Email with HTML Body using C++

In the previous example, we have created an email with plain text. However, most of the emails these days contain an HTML body for a fine presentation of the email’s content. In such a case, you can configure Aspose.Email and set the HTML-based body of the email. For this, just use MailMessage->set_HtmlBody(System::String) and pass to it the HTML content. The following code sample shows how to create an email with an HTML body using C++.

Set Encoding for Outlook Email using C++

Aspose.Email for C++ also lets you define the encoding standard to guide the browser about how to deal with characters in the email. For setting the particular encoding standard, you can use MailMessage->set_BodyEncoding(System::Text::Encoding) method. The following code sample shows how to create an email with particular encoding using C++.

Save Outlook Message as Draft using C++

You can also save the newly created Outlook email message as a draft. The following are the steps to perform this operation:

The following code sample shows how to create an email as a draft using C++.

Live Demos


In this article, I have shown you how to create Outlook emails within C++ applications. The C++ code samples demonstrated how to create MSG, EML or EMLX emails with text/HTML body or a particular encoding. You can explore more about how to deal with Outlook emails and other items using Aspose.Email for C++.

See Also