This is how I create the table now and send it by email. What I would like to do is instead of creating a table and sending it as text in an email, I would like to create a csv file and attach it to this email, and then send it. can someone please help show me how to do this? thank
using (MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(csv)))
{
try
{
string to = "";
string from = "";
string subject = "Order";
string body = sb.ToString();
SmtpClient SMTPServer = new SmtpClient("127.0.0.1");
MailMessage mailObj = new MailMessage(from, to, subject, body);
mailObj.Attachments.Add(new Attachment(stream, new ContentType("text/csv")));
mailObj.IsBodyHtml = true;
SMTPServer.Send(mailObj);
}
catch (Exception ex)
{ return "{\"Error\":\"Not Sent\"}"; }
}
source
share