发送电子邮件ASP.NET

时间:2015-11-09 22:02:55

标签: c# html asp.net .net email

我正在创建一个工作申请表单,申请人申请并点击提交时。信息存储在数据库中,也会发送到电子邮件中。我运行我的代码,一切正常,没有错误显示。唯一的问题是电子邮件没有发送。提前谢谢!

以下是代码:

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");
            }
        }
    }

0 个答案:

没有答案