用户在asp.net c中完成注册时如何发送带验证链接的电子邮件# [英] how to send email with verification link when user completes his registration in asp.net c#

查看:60
本文介绍了用户在asp.net c中完成注册时如何发送带验证链接的电子邮件#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在asp.net中完成注册时如何发送带验证链接的电子邮件c#这是我的代码...请告诉我如何在创建帐户时在用户的电子邮件中发送验证链接..... PLZ帮助....提前感谢







how to send email with verification link when user completes his registration in asp.net c# this is my code...plz tell me that how can i send verification link on users email when he create an account.....plz help....thanks in advance



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Linq;
using System.Xml.Linq;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Configuration;

public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
     SqlConnection con = new SqlConnection(
     ConfigurationManager.ConnectionStrings["BMCConnectionString"].ConnectionString);

    // open the data connection.  
    con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
     if (IsPostBack)
    {
        Response.Write("<script>alert('Thanking you .....Registration Successful')</script>");
        TextBoxDate.Text = DateTime.Now.ToString();

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BMCConnectionString"].ConnectionString);

        con.Open();
        string insCmd = "insert into Registration(UserName, Password, RePassword, Email, FullName ,Date ,Month, Year, Gender, Area, Date1) values (@UserName, @Password, @RePassword, @Email, @FullName ,@Date ,@Month, @Year, @Gender, @Area, @Date1)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        insertUser.Parameters.AddWithValue("@UserName", TextBoxUN.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        insertUser.Parameters.AddWithValue("@RePassword", TextBoxRP.Text);
        insertUser.Parameters.AddWithValue("@Email", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@FullName", TextBoxFN.Text);
        insertUser.Parameters.AddWithValue("@Date", DropDownListDate.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Month", DropDownListMonth.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Year", DropDownListYear.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Gender", RadioButtonList1.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Area", DropDownListArea.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Date1", TextBoxDate.Text);
{
                //create the mail message
                MailMessage mail = new MailMessage();
                //set the addresses
                mail.From = new MailAddress("salvevishal9@gmail.com");
                mail.To.Add(TextBoxEA.Text);
                //set the content
                mail.Subject = "This is an email";
                mail.Body = "this is the body content of the email.";
                //send the message
                
                SmtpClient smtp = new SmtpClient("smtp.gmail.com");
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.Send(mail);

        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();

        }
        catch (Exception er)
        {
            Response.Write(er);
        }
    }
}

推荐答案

你实际上在一个问一些事情问题,所以我必须打破它。这些将是相当高级别的步骤,希望足以让您走上正确的道路。如果你仍然陷入困境,那么可能会问一个与你坚持的步骤有关的问题...



1。电子邮件发送工具

考虑设置一个专门的类来处理电子邮件的发送。这个类看起来像这样:简单的SMTP E- C#中的邮件发件人...控制台应用程序 [ ^ ]



2。数据库更改

您的用户表(类型位字段)上需要一个标记,表示他们是否已经验证了自己。



3。创建验证页面

创建一个新页面,该页面是链接的目标。此页面将检查用户ID的查询字符串(建议您加密这些字符串)。当他们输入密码时,它会对此进行验证,然后在新列上将其标记为已验证。



然后您只需在电子邮件正文中添加一个链接到上一页将用户ID作为加密参数。



希望有所帮助。
You''re actually asking a several things in one question, so I''ll have to break it down. These will be fairly high level steps, hopefully enough to get you on the right path. If you''re still stuck then maybe ask a question related specifically to the step you''re stuck on...

1. Email Sending util
Consider setting up a dedicated class to handle the sending of email. This class will look something like this: Simple SMTP E-Mail Sender in C#… Console application[^]

2. Database change
You need a flag on your user table (field of type bit) which represents whether they''ve verified themselves or not.

3. Creating the verification page
Create a new page which is the target of the link. This page will check the query string (recommend you encrypt these) for the user''s id. When they enter their password it would validate this and then mark them as verified on the new column.

Then you just add a link in the email body to the above page with the user id as an encrypted parameter.

Hope that helps.


这篇关于用户在asp.net c中完成注册时如何发送带验证链接的电子邮件#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆