2013-10-18 169 views
-3

我想發送確認電子郵件給剛剛在網站上註冊的用戶。爲了找到解決方案,我多次搜索了它,但目前爲止沒有任何工作。你能幫我解決這個問題嗎? 在此先感謝!註冊時發送確認郵件到電子郵件

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

該代碼與發送電子郵件無關。你嘗試了什麼,發生了什麼? – CodeCaster

+0

我會基於你對'asp.net'新手'這個事實來提出這個建議,所以我會假設你還沒有聽說過它。但asp.net帶有它自己的成員資格系統,這使得所有這些工作變得簡單容易:http://www.codeproject.com/Articles/342061/Understanding-ASP-NET-Roles-and-Membership-A開始由於您的問題缺乏對特定編程問題的關注,因此我認爲您現在不會得到更有建設性的建議。 –

+0

如果你真的用Google搜索,你會發現很多文章,這裏有一個樣本http://articlemirror.blogspot.in/2013/06/how-to-send-email-with-verification.html – coder

回答

相關問題