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;
}
MemoryStream
is entirely in memory. If you wanted a file you'd needFileStream
.