title: Send Uploaded File as attachment
body: <p>I am trying to get an uploaded file to be sent as an attachment in my <code>ashx</code> file. Here is the code I am using:</p>
  
  <pre><code>HttpPostedFile fileupload = context.Request.Files[0];
  
  //filename w/o the path
  string file = Path.GetFileName(fileupload.FileName);
  
  MailMessage message = new MailMessage();
  
  //*****useless stuff********
  message.To.Add("abc@xxx.com");
  message.Subject = "test";
  message.From = new MailAddress("test@aaa.com");
  message.IsBodyHtml = true;
  message.Body = "testing";
   //*****useless stuff********
  
  //Fault line
  message.Attachments.Add(new Attachment(file, MediaTypeNames.Application.Octet))
  
  //Send mail 
  SmtpClient smtp = new System.Net.Mail.SmtpClient("xxxx", 25);
  smtp.UseDefaultCredentials = false;
  smtp.Credentials = new NetworkCredential("xxx", "xxxx");
  smtp.Send(message);
  </code></pre>
  
  <p>I am able to send the email without the attachment. 
  Do I need to save the file first and then add to attachment?</p>