使用asp.net发送电子邮件? [英] using asp.net for send email?
问题描述
亲爱的所有人,
我创建了一个网页,这里按下提交按钮,详细信息意味着:姓名,电子邮件,密码,确认密码,地址
这些详细信息存储在数据库表中(表2)
这里我的要求是:一旦提交上面的详细信息并自动发送邮件(输入任何电子邮件)这是正常工作
但是一旦在数据库表中输入1个客户详细信息存储并将自动收到电子邮件并且第二个客户在数据库中输入详细信息存储表并将自动获得邮件
但这里的小错误意味着一旦2个客户输入现有邮件ID,这些邮件ID和密码将转到第一个客户邮件,如下例
ex:
- 第一位客户 -
名称:aaa
邮件:aaa@gmail.com
密码:123
确认密码:123
地址:nnnn
--2客户 -
名称:ttt
mail:aaa@gmail.com
密码:456
确认密码:456
地址:uuuu
这里邮件ID和密码将转到第一位客户
这里我不想转到第一个客户邮件只是我想只验证已存在的邮件
请检查以下代码:
Dear All,
I created one webpage and here once press submit button that details means: name, email,password,confirm password,address
these details store in database table(Table_2)
here my requirement is: once submit above details and automatically will send to mail(enter any email) this is working properly
but once enter 1 customer details store in database table and will get email automatically and 2nd customer enter details store in database table and will get mail automatically
but here small error means once 2 customer enter existing mail id these mail id and password will go to 1st customer mail like below example
ex:
--1st customer--
name:aaa
mail:aaa@gmail.com
password:123
confirm password:123
address: nnnn
--2nd customer--
name:ttt
mail:aaa@gmail.com
password:456
confirm password:456
address: uuuu
here mail id and password will goto 1st customer
here i want not goto 1st customer mail just i want only validation already exist mail
plase check below code:
private void load()
{
string strConnection = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
string strSelect = "SELECT Email,Password FROM Table_2 WHERE Email=@Email";
SqlConnection connection = new SqlConnection(strConnection);
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = CommandType.Text;
command.CommandText = strSelect;
SqlParameter email = new SqlParameter("@Email", SqlDbType.VarChar, 50);
email.Value = TextBox2.Text.Trim().ToString();
command.Parameters.Add(email);
//Create Dataset to store results and DataAdapter to fill Dataset
DataSet dsPwd = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter(command);
connection.Open();
dAdapter.Fill(dsPwd);
connection.Close();
if (dsPwd.Tables[0].Rows.Count > 0)
{
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(TextBox2.Text.ToString());
loginInfo.From = new MailAddress("mailid");
loginInfo.Subject = "Register Information";
loginInfo.Body = "Email: " + dsPwd.Tables[0].Rows[0]["Email"] + "<br /><br />Password: " + dsPwd.Tables[0].Rows[0]["Password"] + "<br /><br />";
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("mailid", "1234");
smtp.Send(loginInfo);
}
else
{
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int userId = 0;
string constr = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("sp_Table_2"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", TextBox1.Text.Trim());
cmd.Parameters.AddWithValue("@Email", TextBox2.Text.Trim());
cmd.Parameters.AddWithValue("@Password", TextBox3.Text.Trim());
cmd.Parameters.AddWithValue("@ConfirmPassword", TextBox4.Text.Trim());
cmd.Parameters.AddWithValue("@Address", TextBox5.Text.Trim());
cmd.Connection = con;
con.Open();
userId = Convert.ToInt32(cmd.ExecuteScalar());
load();
con.Close();
}
}
string message = string.Empty;
switch (userId)
{
case -1:
message = "name already exists.\\nPlease choose a different username.";
break;
case -2:
message = "email already exists.";
break;
default:
message = "successful.";
break;
}
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('" + message + "');", true);
}
}
请回复我
please reply me
推荐答案
userId = Convert.ToInt32(cmd.ExecuteScalar());
//load();
con.Close();
}
}
string message = string.Empty;
switch (userId)
{
case -1:
message = "name already exists.\\nPlease choose a different username.";
break;
case -2:
message = "email already exists.";
break;
default:
load(); // send mail only when user name and password correct case
message = "successful.";
break;
}
这篇关于使用asp.net发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!