0

I am creating a job application web form, where applicants apply and when submit is clicked. The information is stored in a database and it is also sent to an email. I ran my code and everything works with no error showing. The only problem was that the email was not sent. Thanks in advance!

Here is the code:

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            string fileName1 = Server.MapPath("~/App_Data/Applicant.txt");
            string mailBody = File.ReadAllText(fileName1);
            mailBody = mailBody.Replace("##position##", lblPosition.Text);
            mailBody = mailBody.Replace("##firstName##", txtFirstName.Text);
            mailBody = mailBody.Replace("##lastName##", txtLastName.Text);
            mailBody = mailBody.Replace("##phone##", txtPhone.Text);
            mailBody = mailBody.Replace("##email##", txtEmail.Text);
            MailMessage myMessage = new MailMessage();
            myMessage.Subject = "Wired Job Applicant";
            myMessage.Body = mailBody;
            myMessage.From = new MailAddress("intern2@wireddistributing.com", "Sender Name");
            myMessage.To.Add(new MailAddress("intern2@wireddistributing.com", "Receiver Name"));
            myMessage.ReplyToList.Add(new MailAddress(txtEmail.Text));
            SmtpClient mySmtpClient = new SmtpClient();
            mySmtpClient.Send(myMessage);

            using (WiredEntities myEntities = new WiredEntities())
            {
                Applicant myApplicant;

                myApplicant = new Applicant();
                myEntities.Applicants.Add(myApplicant);

                myApplicant.FirstName = txtFirstName.Text;
                myApplicant.LastName = txtLastName.Text;
                myApplicant.Phone = txtPhone.Text;
                myApplicant.Email = txtEmail.Text;

                Job_Applicant jobApplication;

                jobApplication = new Job_Applicant();
                jobApplication.DateSubmitted = DateTime.Now;
                myEntities.Job_Applicant.Add(jobApplication);

                jobApplication.ApplicantId = myApplicant.ApplicantId;
                jobApplication.JobId = _id;

                if (FileUpload1.HasFile)
                {
                    string virtualFolder = "~/Resumes/";
                    string phyisicalFolder = Server.MapPath(virtualFolder);
                    string fileName = FileUpload1.FileName;

                    FileUpload1.SaveAs(System.IO.Path.Combine(phyisicalFolder, fileName));
                    jobApplication.FileUrl = virtualFolder + fileName;
                }

                myEntities.SaveChanges();
                Response.Redirect("Careers.aspx");
            }
        }
    }
Ron T
  • 397
  • 1
  • 4
  • 22
  • check your mail setting...first – SANDEEP Nov 10 '15 at 04:22
  • I checked my mail setting, and it is okay. I have another form on a "Contact Us" page, and it works but on this page it doesn't seem to work. @SANDEEP – Ron T Nov 10 '15 at 04:46
  • Never mind, it was already working. For some reason, it just sent it to my junk mail @SANDEEP – Ron T Nov 11 '15 at 19:01

0 Answers0