Quantcast
Channel: ClosedXML - The easy way to OpenXML
Viewing all articles
Browse latest Browse all 1877

New Post: Generate Excel and Add As Email Attachment

$
0
0
I had a similar problem. Solved with highlighted line of code before creating the attachment from memory stream.
using (MemoryStream memoryStream = new MemoryStream())
{
    MailMessage mailMessage = new MailMessage(smtpFrom, smtpTo);

    mailMessage.Subject = subject;
    mailMessage.Body = body;

    __memoryStream.Seek(0, SeekOrigin.Begin);__
    Attachment attachment = new Attachment(memoryStream, "<filename>.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
    mailMessage.Attachments.Add(attachment);

    SmtpClient smtpClient = new SmtpClient(smtpServer);
    smtpClient.Send(mailMessage);

    memoryStream.Close();
}

Viewing all articles
Browse latest Browse all 1877

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>