Excel files are widely used to keep and share data in the form of rows and columns. In addition, you can perform various operations on the Excel data and visually analyze it. In some instances, you have to embed and send the data from an Excel sheet in the email message. To accomplish that, this article covers how to send Excel data in an email’s body programmatically in C# .NET.
C# .NET APIs to Send Excel Data in Email Body
To send the Excel data in email messages, we will use Aspose.Email for .NET. It is a popular and feature-rich API that lets you create and send emails from within your .NET applications. In addition, we will use Aspose.Cells for .NET to convert the Excel sheets into HTML content. You can either download the APIs’ DLLs or install them from NuGet using the following commands.
PM> Install-Package Aspose.Email PM> Install-Package Aspose.Cells
Send Excel Data in Email’s Body in C#
First, we will use Aspose.Cells for .NET to convert the Excel data into HTML so that it can be embedded into the email’s body. After that, we will use Aspose.Email for .NET to compose the email, insert Excel data into the email’s body, and send email. The following are the steps to send Excel data in an email’s body in C#.
- Load Excel workbook using Aspose.Cells’ Workbook class.
- Save the workbook to MemoryStream in HTML format.
- Read the HTML from the stream into a string object.
- Create a new MailMessage object and set its HtmlBody to the HTML content.
- Create and configure the instance of SmtpClient class.
- Send the email using SmtpClient.Send(MailMessage) method.
The following code sample shows how to send Excel data in an email’s body in C#.
Get a Free API License
You can use Aspose APIs without evaluation limitations using a free temporary license.
In this article, you have learned how to embed and send Excel data in an email’s body using C# .NET. You can simply install the mentioned APIs and integrate the provided code into your .NET applications. Besides, you can explore more about the APIs using their documentation given below.
In case you would have any questions, you can post to our forum.