Susanta Rout

Susanta Rout

  • 786
  • 1.1k
  • 126.2k

problem in sending email with attachment

Sep 10 2015 7:56 AM
button click event 
 
protected void btnUpload_Click(object sender, EventArgs e)
{  
  string filepath;
   if(resumeUpload.HasFile)
   {
      filepath = resumeUpload.PostedFile.FileName;
       string body = "My Name :" + txtNamec.Text + "<br/>I am a" + ddlGender.SelectedItem.Text + "<br/>My Email :" + txtEmailc.Text + "<br/>My                   Mobile No :" + txtMobile.Text + "<br/> Course :" + txtCourse.Text + "<br/> Location" + txtLocation.Text;
            Label1.Text = sv.carrer(body,filepath);
}
}
 
 
my class
 
public string carrer(string email,string filepath)
{
try
{
string to = "[email protected]";
string from = "[email protected]";
MailMessage msg = new MailMessage(from, to);
string mailbody = email;
msg.Subject = "Smart Vidyarthi Call Back";
msg.Body = mailbody;
msg.Attachments.Add(new Attachment(filepath));
msg.BodyEncoding = Encoding.UTF8;
msg.IsBodyHtml = true;
msg.Priority = MailPriority.High;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
System.Net.NetworkCredential basicredenital = new System.Net.NetworkCredential("[email protected]", "password");
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = basicredenital;
client.Send(msg);
return "Message Has Been Sent";
}
catch (Exception ex)
{
throw ex;
}
}
 
exception: file not found eception 
 

Answers (17)