-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");
        }

    }
}
4

1 回答 1

0

我相信发送消息最简单的解决方案是通过 ASP.NET Mailing 上的第一个 Google 链接。我想知道什么不适合你:

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

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

于 2013-10-18T07:35:12.197 回答