Skip to content

Instantly share code, notes, and snippets.

@conholdate-gists
Created January 5, 2024 08:15
Show Gist options
  • Save conholdate-gists/99176fd91610c9f4936e693ff236d3b4 to your computer and use it in GitHub Desktop.
Save conholdate-gists/99176fd91610c9f4936e693ff236d3b4 to your computer and use it in GitHub Desktop.
Email Excel Sheet in C# | Email Excel XLS XLSX Spreadsheet | Send Gmail Excel
// 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, Aspose.Cells.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
Aspose.Email.MailMessage message = new Aspose.Email.MailMessage();
message.HtmlBody = strHtmlBody;
message.Subject = "Inline Excel Message";
message.From = "sender@abc.com";
message.To = "receiver@xyz.com";
message.IsBodyHtml = true;
Aspose.Email.Clients.Smtp.SmtpClient client = new Aspose.Email.Clients.Smtp.SmtpClient();
client.Host = "smtp.gmail.com";
client.Username = "Username";
client.Password = "Password";
client.Port = 587;
client.SecurityOptions = Aspose.Email.Clients.SecurityOptions.Auto;
client.Send(message);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment