Send Word Document in Email Body using C#

Send word document in email c#

The presentation of the emails’ body is one of the important factors to engage the readers. Therefore, emails are well formatted using headings, subheadings, tables, images, and etc. However, most of the built-in email editors do not provide advanced formatting options. In order to tackle this limitation, this article covers how to compose your emails using Word documents as email body in C#.

C# APIs to Import Word Document to Email

In order to import the content from a Word document, we’ll use Aspose.Words for .NET API. Whereas, to compose and send the email, we’ll leverage the capabilities of Aspose.Email for .NET. Both of the above-mentioned APIs can either be downloaded as DLL or installed via NuGet.

Download DLLs

Install via NuGet

PM> Install-Package Aspose.Words
PM> Install-Package Aspose.Email

Send Word Document in Email Body using C#

1. Load the Word document using the Aspose.Words.Document class and save it as MHTML into a MemoryStream object.

2. Load the MHTML from the MemoryStream object to Aspose.Email.MailMessage object and set subject, to and from fields of the email.

3. Set up SMTP client using Aspose.Email.Clients.Smtp.SmtpClient class and send the email.

Source Code

The following is the complete source code of importing MS Word document as an email body using C#.

Get a Free API License

You can try the API without evaluation limitations for free. Get a free temporary license now.

Conclusion

In this article, you have learned how to import a Word document as an email body using C#. Furthermore, the code sample has shown how to send the composed email message using an SMTP client. You can explore more about the APIs being used in the article by visiting the following documentations.

See Also