当用户在asp.net c#中完成注册时如何发送带有验证链接的电子邮件这是我的代码......请告诉我,当他创建帐户时我如何在用户电子邮件上发送验证链接......请帮助。 ...提前致谢
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);
}
}
}
}