我想向刚刚注册到该网站的用户发送一封确认电子邮件。我用谷歌搜索了几次以找到解决方案,但到目前为止没有任何效果。你能帮我写代码吗?提前致谢!
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");
}
}
}