I am using ASP.NET 3.5 and C# for developing a web application on helpdesk.
I am send email to the admin when user lodges a complaint.
My issue is when the mail with attachment(word,excel,jpg,bmp etc)
is sent to admin by the user the attachment contains no data.
Here is the code sample I used:
MailMessage mm = new MailMessage();
mm.To.Add(mail1@abcd.com);
mm.From = new MailAddress("web@abcd.com");
if (FileUpload1.HasFile) /// for checking if mail has attachment
{
mm.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, ileUpload1.FileName));
}
mm.body="Test Message";
mm.IsBodyHtml = true;
//neceessary credentials are specified in web.config file
SmtpClient ss = new SmtpClient();
ss.Send(mm);
To send the mail with attachment, you must first save the file from the fileuploader on your server and then you can send it in mail as an attachment. The current problem over here is, you are directly trying to send the file in the mail from fileupload control.
Once the mail is sent with attachment, then you can delete the saved file from your server.