通过电子邮件将用户的ID发送给他们

时间:2018-05-06 23:32:11

标签: c# asp.net email webforms

我可以在将数据提交到sql数据库后从用户填写的表单中获取一些信息后发送给用户的电子邮件。我用带有占位符的HTML模板实现了这一点,然后根据我在asp.net中的代码隐藏使用C#替换它们。但我已经尝试确保我也向他们发送了他们在Microsoft SQL Server数据库中唯一生成的应用程序否。例如,应用程序编号:CHV1800000001这是唯一创建的,我想在提交表单后通过电子邮件将其发送给每个用户。请帮忙。

using (StreamReader reader = new StreamReader(Server.MapPath("~/Account/RegMessage.html")))
        {

            MailText = reader.ReadToEnd();



            //Repalce [userdetails] = user details  
           // MailText = MailText.Replace("[ApplicationID]", reg.ApplicationID.ToString());
            MailText = MailText.Replace("[FirstName]", txtFN.Text.Trim());
            MailText = MailText.Replace("[Surname]", txtLN.Text.Trim());
            MailText = MailText.Replace("[MatricNo]", txtmatric.Text.Trim());
            MailText = MailText.Replace("[DateApplied]", txtdap.Text.Trim());



            MailMessage msg = new MailMessage();
            msg.To.Add(txtemail.Text.ToString());
            MailAddress from = new MailAddress("scholarships@optimumresourcesmgt-ng.com", "CHEVRON Scholarships");
            msg.From = from;
            msg.Subject = "Successful Application Confirmation";
            msg.IsBodyHtml = true;
            //BuildEmailMsg();

            msg.Body = MailText;
            SmtpClient smtpClient = new SmtpClient("smtp.1and1.com", 587);
            smtpClient.EnableSsl = true;
            smtpClient.Credentials = new System.Net.NetworkCredential("scholarships@optimumresourcesmgt-ng.com", "Optimuma@123");
            smtpClient.Send(msg);
            InsertRegistration();
            lblMessage.Visible = true;
            lblMessage.Text = "Application successfully submitted. We will email your Applicaion details to you. Please check your email both spam and inbox folders.";
            lblMessage.ForeColor = System.Drawing.Color.Green;
            //End of Send Mail Region

由于

1 个答案:

答案 0 :(得分:0)

您是通过SQL IDENTITY增加唯一性吗?

如果是,那么您可以使用scope_identity来获取值以及insert语句。