注册时向电子邮件发送确认邮件

时间:2013-10-18 07:29:35

标签: c# asp.net email login

我想向刚刚注册该网站的用户发送确认电子邮件。我搜索了几次以找到解决方案,但到目前为止没有任何工作..你能帮我解释一下代码吗? 提前谢谢!

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Data;

public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

    if (IsPostBack)
    {
        SqlConnection con = new     SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr    ing);
        con.Open();
        string cmdStr = "Select count(*) from Table where Username='" +     TextBox1Username.Text + "'";
        SqlCommand userExist = new SqlCommand(cmdStr, con);
    /*  int temp = Convert.ToInt32(userExist.ExecuteScalar().ToString());
        con.Close();
      if (temp == 1)
        {
            Response.Write("username already exists");
        } */
    }
}



protected void Submit_Click(object sender, EventArgs e)
{

    SqlConnection con = new     SqlConnection(ConfigurationManager.ConnectionStrings["RegisConnectionString"].ConnectionStr    ing);
    con.Open();
    string insCmd = "Insert into Register (Username, Password, EmailAddress,Fullname,     City) values (@Username, @Password, @EmailAddress, @Fullname, @City)";
    SqlCommand insertUser = new SqlCommand(insCmd, con);
    insertUser.Parameters.AddWithValue("@Username", TextBox1Username.Text);
    insertUser.Parameters.AddWithValue("@Password", TextBox2Password.Text);
    insertUser.Parameters.AddWithValue("@EmailAddress", TextBox4Email.Text);
    insertUser.Parameters.AddWithValue("@Fullname", TextBox5FullName.Text);
    insertUser.Parameters.AddWithValue("@City", TextBox6City.Text);
    {
        try
        {

                insertUser.ExecuteNonQuery();
                con.Close();
                Response.Redirect("Login.aspx");

        }
        catch (Exception er)
        {
            Response.Write("error: " + er.Message + " ,please try registering again");
        }

    }
}

1 个答案:

答案 0 :(得分:0)

我认为发送邮件的最简单的解决方案是通过ASP.NET Mailing上的第一个Google链接。我想知道这对你有用的是什么:

http://weblogs.asp.net/scottgu/archive/2005/12/10/432854.aspx

我相信MailMessage的对象表示非常清楚,否则就是关于SMTP设置。

相关问题