2013-10-18 170 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

回答

相关问题