62,046
社区成员
发帖
与我相关
我的任务
分享
void semdMail(string subjects)
{
System.Net.Mail.SmtpClient mail = new System.Net.Mail.SmtpClient();
mail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
mail.Host = "smtp.163.com";//发送服务的SMTP服务地址
mail.Credentials = new System.Net.NetworkCredential("执行发送的邮箱", "密码");
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("邮箱@163.com", E_mail.Text); //
message.Body = 发送的邮件内容;//这个地方你可以用一个参数来实现生成新的密码写在邮件正文部分了:
message.Subject = 发送的邮件标题;
message.Priority = System.Net.Mail.MailPriority.High;
try
{
mail.Send(message);
return;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return;
}
}
string sqlconn = System.Configuration.ConfigurationManager.ConnectionStrings["MDBConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection(sqlconn);
myConnection.Open();
SqlCommand myCommand = new SqlCommand("select Member_Email from MDB where
Member_ID='" + Session["UserID"].ToString() + "'", myConnection);
SqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
if (ProdectPWD.Text.ToString() == myReader.GetString(1) && ProdectKey.Text.ToString() == myReader.GetString(2))
{
string UserEmail = myReader.GetString(3).Trim();//找到用户的Email
//生成随机密码,已便发送到用户邮箱
Random RandomNum_First = new Random((int)DateTime.Now.Ticks);
System.Threading.Thread.Sleep(RandomNum_First.Next(50));
int int_Red = RandomNum_First.Next(10000, 999999);
//发送随机密码到客户邮箱
System.Net.Mail.MailMessage myMail = new System.Net.Mail.MailMessage();
myMail = new System.Net.Mail.MailMessage("自己的油箱名@163.com", UserEmail);
myMail.Subject = "XXXX开发公司!";//邮件发送标题
myMail.Body = "请您使用" + int_Red + "这个密码登陆并及时修改您的密码
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient("smtp.163.com", 25);
client.Credentials = new System.Net.NetworkCredential("自己的邮箱名", "邮箱密码");
client.Send(myMail);
}
}