How to Send Word Document by Email using C#

In this easy tutorial, we will learn how to send Word Document by email using C#. In the following example, you will see how easy it is to send Word Document in email body using C#. You may use the example in any of the commonly available operating system like Linux, macOS, or Windows.

Steps to Send Word Document by Email using C#

  1. Install Aspose.Words and Aspose.Email libraries from NuGet package manager tool in Visual Studio.
  2. Initialize Document class object to load the document to send as email
  3. Save the document as stream to an intermediate MHTML format
  4. Instantiate MailMessage class instance to load the MHTML as MailMessage and set its properties
  5. Instantiate SMTP client and send the Word document as email using C#

In above steps, we will load the Word document for sending as email in first step. Then we will save the loaded document to a stream in intermediate MHTML format. In subsequent steps, we will load the MHTML using MailMessage class and set it’s mail properties. Finally, an instance of SMTP client class will be instantiated to create email from DOCX in C#.

Code to Send Word Document by Email using C#

In above example, we have send Word Document in email body using C# by adopting two steps approach. In first step, we have loaded and saved the DOCX as an intermediate format MHTML file using streams. Then in second step, we have loaded the MHTML in stream using MailMessage. Finally, by using SMTP client, we send Document by email in C#.

In this simple topic, we have explored how to create email from DOCX using C#. However, if you are looking for conversion of DOCX to MD file, refer to the article on how to convert Word to Markdown using C#.

 English