Does a MailMessage Attached to a Stream Generate a File?

37 Views Asked by At

In one method I have the below code:

var newMessage = new MailMessage();
newMessage.Attachments.Add(new Attachment(ToStream("testAttachment"), MediaTypeNames.Text.Plain));

Then I have this method which is called from above. I have done some research but am not sure still, does the Stream method actually generate a File on my machine or in this case is it just adding an attachment?

If it does actually create a file on my machine, where would it go as I am not defining a path? Then id also want to know how I can add an attachment to Email from a string without generating a file on my machine

private Stream ToStream(string text)
{
   var stream = new MemoryStream();
   var writer = new StreamWriter(stream);
   writer.Write(text);
   writer.Flush();
   stream.Position = 0;
   return stream;
}
0

There are 0 best solutions below