.Net – Sending Email with In Memory Attachment

This VB.Net code takes the FileUpload control’s PostedFile and without saving it to the filesystem attaches it to an MailMessage and sends an email.


  • No threading, read/write permissions needed.
  • One line of code.

Front End:

<asp:FileUpload ID="fileUpload" runat="server" />


Dim m As New MailMessage()
m.Attachments.Add(New Attachment(fileUpload.PostedFile.InputStream, fileUpload.FileName))

TikiWiki – Tracker Email Subject Improvement-Modification


The template for the Tracker email is here:

I changed it to this so that it would improve the way it looks in emails:

{$mail_trackerName}{tr} - #{/tr}{$mail_itemId}{tr} modified.{/tr}