C # email object for streaming to application

I am trying to create and send an email attachment from an object that is a list of lists. I found a well-documented answer here , but still has some confusion.

It mentions "get some binary data"

//Get some binary data byte[] data = GetData(); 

I checked my data:

 Console.WriteLine(ieLog.FirstName + "." + ieLog.LastName); 

I think my question is how to turn this into a stream, if there is more than one, then use:

 //save the data to a memory stream MemoryStream ms = new MemoryStream(data); 

and then send the attachment?

Thanks for any help or tips.

I would like to be excel doc or csv if I can't figure it out. I'm sure there are already classes for this kind of thing where newb is looking for this kind of information?

+2
source share
1 answer

I wrote it directly in the browser, but it should be in order:

 ... byte[] data = ASCIIEncoding.Default.GetBytes(ieLog.FirstName + "." + ieLog.LastName); using(MemoryStream ms = new MemoryStream(data)) { mail.Attachments.Add(new Attachment(ms, "myFile.csv", "text/csv" )); SmtpClient smtp = new SmtpClient("127.0.0.1"); smtp.Send(mail); } 
+4
source

All Articles