Free Support Forum - aspose.com

Sending Excel sheet as message body (not attachment)

Hi,

We have an excel file that we would like to make part of message body and send it to our clients via smtp. File has confidential data so we can not share that and you can use any sample file. Is it possible to achieve using Aspose.Email API?

@RobertVille

You can send Excel sheet in message body by converting it to HTML. Please find below the sample code.

// Load the desired workbook from disk
Workbook workbook = new Workbook(dataDir + “Data.xlsx”);

// Save the workbook to Memory Stream in HTML format
MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.Html);
ms.Position = 0;

// Define a StreamReader object with the above MemoryStream
StreamReader sr = new StreamReader(ms);

// Load the saved HTML from StreamReader now into a string variable
string strHtmlBody = sr.ReadToEnd();

// Define a new Message object and set its HtmlBody
MailMessage message = new MailMessage();
message.HtmlBody = strHtmlBody;

Please follow the link below for more details:
https://docs.aspose.com/display/emailnet/Using+a+Microsoft+Excel+Worksheet+as+the+Message+Body+and+Sending+Email