MailMessage mail=new MailMessage (); //MailEncoding encod=new MailEncoding (); mail.From =TextBox1.Text; // accepting a value from textbox. mail.To =TextBox2.Text; mail.Subject =TextBox3.Text; mail.Body =TextBox4.Text ; mail.BodyFormat =MailFormat.Html ; String strdir="D:\\temp\\"; String strfilename =Path.GetFileName (File1.PostedFile.FileName ); File1.PostedFile.SaveAs (strdir+strfilename); mail.Attachments.Add (new MailAttachment (strdir+strfilename));
try { SmtpMail.SmtpServer ="localhost"; SmtpMail.Send (mail); } catch(Exception ex) { Response.Write("Exception Occured: " +ex); } finally { Response.Write("Your E-mail has been sent sucessfully"); }
con=new SqlConnection("user id=sa;password=rmax;data source=javastre-688yoi;database=master"); con.Open (); com=new SqlCommand ("insert into mail values('"+strdir+"')",con); com.ExecuteNonQuery (); Response.Write ("inserted"); }query:1.how to attach a file and send it . 2.is the above program correct. 3.String strfilename =Path.GetFileName (File1.PostedFile.FileName ); how do we accept valuefrom textbox and attach it.