I am writing a program to attach a file to email. Currently I am saving the file using I do not want to store the file in the disk, I want to store the file in memory and send it to the Here is sample code. 1 edit You specify other file types by System.Net.Mime.MimeTypeNames such as FileStream in the disk, and then I
System.Net.Mail.MailMessage.Attachments.Add (New System NET.Mail. Attachments ("File Name"));
attachment from the storage stream.
System.IO.MemoryStream ms = new System.IO .MemoryStream (); System.IO.StreamWriter Author = New System. Io Serial (ms); Author. Write ("Hello your sample file"); Writer.flush (); Writer.Dispose (); System.Net.Mime.ContentType ct = New System.Net.Mime.ContentType (System.Net.Mime.MediaTypeNames.Text.Plain); System.Net.Mail.Attachment Attached = New System.Net.Mail.Attachment (MS, CT); Attach. Content Disposition. Filename = "myFile.txt"; // I think you know about sending an email address with an email attachment after sending an email address. Close ();
System.Net.Mime Depending on the mime type you need to specify the correct extension in the file extension, for example
"myFile.pdf" . .
Comments
Post a Comment