Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取用户';s的id通过电子邮件发送给他们_C#_Asp.net_Email_Webforms - Fatal编程技术网

C# 获取用户';s的id通过电子邮件发送给他们

C# 获取用户';s的id通过电子邮件发送给他们,c#,asp.net,email,webforms,C#,Asp.net,Email,Webforms,我能够在将用户的数据提交到sql数据库后向用户发送电子邮件,从他们填写的表单中获取一些信息。我通过一个带有占位符的HTML模板来实现这一点,然后使用C#在asp.net中的代码隐藏中替换它们。但我已尝试确保我也向他们发送了在Microsoft SQL Server Datatabase中唯一生成的应用程序No。例如,申请编号:CHV180000001这是唯一创建的,我希望在提交表单后通过电子邮件将其发送给每个用户。请帮忙 using (StreamReader reader = new Stre

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

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

谢谢

您是否通过SQL标识递增unique


如果是,则可以使用scope_identity和insert语句获取值。

从SQL获取值,然后将其包含在发送的电子邮件中?这与javascript无关。请根据具体情况标记问题problem@charlietfl谢谢我会改正的。请提供任何指南或示例?加载表单时,还应在隐藏的服务器控件中呈现applicationId,然后在发送电子邮件时从隐藏控件获取值。您可以做的其他事情是从数据库获取applicationId,并在发送电子邮件之前将其包含在电子邮件中。谢谢!是的,我使用了scope_identity或OUTPUT Inserted.ApplicationID来获取值以及insert语句。如何将其构建到我的邮件中,并在单击“提交”按钮后发送给每个用户?谢谢。我很感激。请给我一个示例邮件设置,获取自动生成的用户id?SqlConnection con=newsqlconnection(…);con.Open();string query=“插入用户(姓名、消息、电话)值('Joe','Demo','12345');选择SCOPE_IDENTITY();”;SqlCommand cmd=新的SqlCommand(查询,con);int userID=Convert.ToInt32(cmd.ExecuteScalar());使用此变量附加电子邮件正文。你是个了不起的人!您的意思是变量:int UserID=Convert.ToInt32(cmd.ExecuteScalar());或者全部:你可以在我的第一个问题中找到我的电子邮件正文。我使用的是一个html模板.int UserID=Convert.ToInt32(cmd.ExecuteScalar());只有这一行。它将为您提供一个id,您可以对应用程序id使用相同的概念