Why to Convert
Converting email messages from one format to another is a common requirement for many C++ developers. For example, you may need to convert an MSG file format to HTML, and then export the HTML to XPS. This is a useful feature for applications that need to display emails in a different format.
How Aspose.Total Helps for MSG to XPS Conversion
Aspose.Total for C++ is a comprehensive suite of APIs that can help you add email conversion features to your applications. It includes two APIs that are specifically designed for this purpose: Aspose.Email for C++ and Aspose.Words for C++.
Aspose.Email for C++ is a powerful API that enables you to convert MSG files to HTML. It supports a wide range of features, including the ability to read and write MSG files, convert MSG files to HTML, and more.
Aspose.Words for C++ is a powerful API that enables you to export HTML to XPS. It supports a wide range of features, including the ability to read and write HTML files, convert HTML to XPS, and more.
By using Aspose.Total for C++, you can easily add email conversion features to your applications. It provides a comprehensive suite of APIs that can help you quickly and easily convert MSG files to HTML and then export the HTML to XPS.
C++ API to Convert MSG to XPS
- Open MSG file using MailMessage class reference
- Convert MSG to HTML by using Save member function
- Load HTML by using Document class
- Save the document to XPS format using Save method and set Xps as SaveFormat
Get Started with C++ File Format APIs
Install from command line as nuget install Aspose.Total.Cpp
or via Package Manager Console of Visual Studio with Install-Package Aspose.Total.Cpp
.
Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads .
// load the MSG file to be converted
System::SharedPtr<MailMessage> msg = MailMessage::Load(u"sourceFile.msg");
// save MSG as a HTML
msg->Save(u"HtmlOutput.html", SaveOptions::get_DefaultHtml());
// load HTML with an instance of Document
System::SharedPtr<Document> doc = System::MakeObject<Document>(u"HtmlOutput.html");
// call save method while passing Xps as save format
doc->Save(u"convertedFile.Xps");
Parse MSG File via C++
Not only you can convert your MSG to XPS, but you can read, manipulate, and parse MSG document. You can get subject, address, body, recipients information of the email by using MapiMessage class of Aspose.Email for C++ API. For example, you can check for a specific sender email for the conversion by using get_SenderEmailAddress() property.
// create an instance of MapiMessage from file
System::SharedPtr<MapiMessage> msg = MapiMessage::FromFile(dataDir + L"message.msg");
// get subject
System::Console::WriteLine(System::String(L"Subject:") + msg->get_Subject());
// get from address
System::Console::WriteLine(System::String(L"From:") + msg->get_SenderEmailAddress());
// get body
System::Console::WriteLine(System::String(L"Body") + msg->get_Body());
// get recipients information
System::Console::WriteLine(System::String(L"Recipient: ") + msg->get_Recipients());
C++ API to Restrict XPS File Format Editing
You can also add document protection features in your app while exporting the document from MSG to XPS. Adding protection to your document is a simple process, as all you need to do is apply the protection method to your document. You can set protection type to ReadOnly to restrict the user to edit the document.
// create a new document and protect it with a password.
auto doc = System::MakeObject<Document>();
// apply Document Protection.
doc->Protect(ProtectionType::ReadOnly, u"password");
// save the document.
doc->Save(u"DocumentProtection.PasswordProtection.Xps");