Click here to Skip to main content
15,918,003 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void btnSubmit_Click(object sender, EventArgs e)
{
   MailMessage obj = new MailMessage(txtFrom.Text, txtTo.Text, txtSubject.Text, txtBody.Text);
        
   if (Fileupload1.HasFile)
   {
      String FileName = Path.GetFileName(Fileupload1.PostedFile.FileName);
      Fileupload1.PostedFile.SaveAs(Server.MapPath("~\\File\\" + FileName.Trim())); // "
      string path = "~\\File\\" + FileName.Trim(); // "
      lblUpload.Text = "file is uploaded";

      Attachment mail1 = new Attachment(path);  // DirectoryNotFoundException  file or directory cannot be found.

      obj.Attachments.Add(mail1);
   }
   else
   {
      lblUpload.Text = "file not uploaded";
   }

   SmtpClient smt = new SmtpClient();
   smt.Port = 587;
   smt.Port = 465;
   smt.Host = "smtp.gmail.com";
   smt.Host = "smtp.mail.yahoo.com";
   smt.Host = "smtp.live.com";
   smt.EnableSsl = true;
   smt.UseDefaultCredentials = false;
   smt.Credentials = new System.Net.NetworkCredential(txtFrom.Text, txtPwd.Text);

   try
   {
      smt.Send(obj);
   }
   catch(Exception e1)// System.Net.Mail.SmtpException Failur sending mail
   {
      throw e1;
   }
}


[edit]Code block added - OriginalGriff[/edit]
[edit_2]Indentation reduced, missing "}" and //" added to avoid formating problems - Nelek[/edit_2]
Posted
Updated 13-May-14 0:26am
v6
Comments
OriginalGriff 13-May-14 5:44am    
So what is the error?
Is there a message?
What happens that you didn't expect, or doesn't happen that you did?

Use the "Improve question" widget to edit your question and provide better information.

1 solution

sir, as i can see that the variable name "Path" you have written, try debugging it and i am sure that the path you want and the path what is coming in the variable would be far different.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900