In this example, we will explore how to send Word Document by email using C++. In the following example code, you will witness how convenient it is to send DOC in email body using C++. You will just need to make simple API calls and perform few simple steps on MS Windows to achieve this.
Steps to Send Word Document by Email using C++
- Configure Aspose.Words.Cpp and Aspose.Email.Cpp using NuGet package Manager tool
- Add the reference to Aspose::Words and Aspose::Email namespaces
- Instantiate the Document Class object to DOCX for sending in email body
- Save DOCX to MHTML intermediate format using stream
- Load MHTML using MailMessage Class instance of Aspose.Email and set message properties
- Initialize the SmtpClient class instance to send MailMessage as email
In these steps, we have noticed how to create email from DOCX using C++. It involves, loading the DOC file for sending as email in first step and saving that as an intermediate MHTML format using stream. Then using MailMessage class instance the intermediate format MHTML is loaded along with setting of other mail properties. Lastly, by using SMTP client class the email is sent.
Code to Send Word Document by Email using C++
In above example, we send Document by email using C++ in two phases. The first phase comprised of loading the DOCX and saving that as MHTML file using streams. In second phase, we have used MailMessage class to load the MHTML and set its other mail properties. Then using SmtpClient class, we dispatch Document by email using C++.
In this topic, we have focused on how to create email from DOCX in C++. If you are interested in conversion of DOCX to Tiff file, you can visit the article on how to convert Word to Tiff using C++.