i try to send email where you can attach a file from your own computer. but the file is no where in the request data when i read the post data. Anybody know why? Code: @if (!IsPost) { <form method="POST"> <div style="padding-left:50px;"> Tell us what you think:<br/><textarea name="msg" rows="3" cols="40"></textarea><br/> Your name:<br/><input type="text" name="name"/><br/> File: <br/><input type="file" name="fileSending"/><br/> <input type="submit" value="Send your message to us"/> </div> </form> } else { try{ var message = Request["msg"]; var name = Request["name"]; <h1>the file info : @Request.Files["fileSending"]</h1> HttpPostedFileBase photo = Request.Files["fileSending"]; var mailMsg = new System.Net.Mail.MailMessage { From = new System.Net.Mail.MailAddress("[email protected]", "christian"), Subject = "test", Body = message, IsBodyHtml = true }; mailMsg.To.Add(new System.Net.Mail.MailAddress("[email protected]", "christian")); mailMsg.ReplyToList.Add(new System.Net.Mail.MailAddress("[email protected]")); @* mailMsg.Attachments.Add(new System.Net.Mail.Attachment(photo.InputStream, photo.FileName)); *@ var smtpClient = new System.Net.Mail.SmtpClient { EnableSsl = false }; smtpClient.Send(mailMsg); <strong>Thank you for your message @name:</strong><br/>@message } catch(Exception e){<p>@e.Message</p>} }
The file itself may not be getting passed as an object correctly. I am assuming that you have a web form to capture the email address and attachment. Check the web form and make sure that the attachment name and the objects are being passed correctly.