-4

当用户在asp.net c#中完成注册时如何发送带有验证链接的电子邮件这是我的代码......请告诉我,当他创建帐户时我如何在用户电子邮件上发送验证链接......请帮助。 ...提前致谢

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Linq;
using System.Xml.Linq;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Configuration;

public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
     SqlConnection con = new SqlConnection(
     ConfigurationManager.ConnectionStrings["BMCConnectionString"].ConnectionString);

    // open the data connection.  
    con.Open();
}
protected void Button1_Click(object sender, EventArgs e)
{
     if (IsPostBack)
    {
        Response.Write("<script>alert('Thanking you .....Registration Successful')</script>");
        TextBoxDate.Text = DateTime.Now.ToString();

        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BMCConnectionString"].ConnectionString);

        con.Open();
        string insCmd = "insert into Registration(UserName, Password, RePassword, Email, FullName ,Date ,Month, Year, Gender, Area, Date1) values (@UserName, @Password, @RePassword, @Email, @FullName ,@Date ,@Month, @Year, @Gender, @Area, @Date1)";
        SqlCommand insertUser = new SqlCommand(insCmd, con);
        insertUser.Parameters.AddWithValue("@UserName", TextBoxUN.Text);
        insertUser.Parameters.AddWithValue("@Password", TextBoxPW.Text);
        insertUser.Parameters.AddWithValue("@RePassword", TextBoxRP.Text);
        insertUser.Parameters.AddWithValue("@Email", TextBoxEA.Text);
        insertUser.Parameters.AddWithValue("@FullName", TextBoxFN.Text);
        insertUser.Parameters.AddWithValue("@Date", DropDownListDate.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Month", DropDownListMonth.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Year", DropDownListYear.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Gender", RadioButtonList1.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Area", DropDownListArea.SelectedItem.Text);
        insertUser.Parameters.AddWithValue("@Date1", TextBoxDate.Text);
        {
            //create the mail message
            MailMessage mail = new MailMessage();
            //set the addresses
            mail.From = new MailAddress("salvevishal9@gmail.com");
            mail.To.Add(TextBoxEA.Text);
            //set the content
            mail.Subject = "This is an email";
            mail.Body = "this is the body content of the email.";
            //send the message

            SmtpClient smtp = new SmtpClient("smtp.gmail.com");
            smtp.Port = 587;
            smtp.EnableSsl = true;
            smtp.Send(mail);

        try
        {
            insertUser.ExecuteNonQuery();
            con.Close();

        }
        catch (Exception er)
        {
            Response.Write(er);
        }
    }
}

}

4

4 回答 4

1

通过asp.net c#发送邮件并不是一件复杂的事情……只要我们知道smtp端口和主机……

        MailAddress to = new MailAddress("Email Id");

        MailAddress from = new MailAddress("Email Id");

        MailMessage mail = new MailMessage(from, to);

        mail.Subject = "write your subject";
        mail.Body = "write your body message";


        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;

        smtp.Credentials = new NetworkCredential(
            "Email Id", "Password");
        smtp.EnableSsl = true;

        smtp.Send(mail);
于 2013-03-15T05:53:48.033 回答
1

找到一个您可以使用的 SMTP 服务器——您的虚拟主机应该为您提供一个可以用于内部应用程序的服务器。如果没有,那么您可以使用 Gmail,如果您有 Gmail 帐户。

用于System.Net.Mail.SmtpClient连接到服务器并发送电子邮件。它有一个简单的重载方法Send,可让您在一次调用中发送邮件。

请注意,System.Web.Mail.SmtpClient已过时。

于 2013-03-14T18:04:03.153 回答
0
//create the mail message

using(SmtpClient smtp = new SmtpClient("localhost"))
{
            MailMessage mail = new MailMessage();
            //set the addresses
            mail.From = new MailAddress("salvevishal9@gmail.com.com");
            mail.To.Add("@Email");
            //set the content
            mail.Subject = "This is an email";
            mail.Body = "this is the body content of the email.";
            //send the message
        smtp.Send(mail);
}

更多信息:

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

于 2013-03-14T18:31:13.157 回答
0
MailAddress to = new MailAddress("Email Id");

MailAddress from = new MailAddress("Email Id");

MailMessage mail = new MailMessage(from, to);

mail.Subject = "write your subject";
mail.Body = "write your body message";


SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;

smtp.Credentials = new NetworkCredential(
    "Email Id", "Password");
smtp.EnableSsl = true;

smtp.Send(mail);
于 2013-05-06T10:20:24.977 回答