当用户在asp.net c中完成注册时如何发送带验证链接的电子邮件# 这是我的代码...请告诉我,当他创建帐户时,如何在用户的电子邮件中发送验证链接..... plz help ....提前感谢
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);
}
}
}
}
答案 0 :(得分:1)
找到可以使用的SMTP服务器 - 您的webhost应该为您提供可用于内部应用程序的服务器。如果没有,那么如果您有Gmail帐户,则可以使用Gmail。
使用System.Net.Mail.SmtpClient
连接到服务器并发送电子邮件。它有一个简单的重载方法Send
,允许您通过一次调用发送邮件。
请注意,System.Web.Mail.SmtpClient
已过时。
答案 1 :(得分: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
答案 2 :(得分:0)
通过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);
答案 3 :(得分: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);