许多网站个人密码丢失,找回密码的办法是:系统自动发送给你以前的密码到你的密保邮箱。以下是自动发送密码的核心代码:注意看加颜色的代码行。
给本方法带参数如:EmailSend("这个参数是邮件的内容-body","收件人-bianbill@126.com","发件人-hsxh@163.ym","发件人密码-1243")
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="mailinfo">邮件的一些属性</param>
/// <param name="smtpname">SMTP事务的主机名称</param>
/// <param name="username">自己的邮箱登录名</param>
/// <param name="pwd">邮箱的密码</param>
/// <returns></returns>
/// <author>Wilhelm Von Arminius</author>
public Boolean EmailSend(MailMessage mailinfo, string username, string adminusername, string adminpwd)
{
bool flag = false;
try
{
MailAddress from = new MailAddress(adminusername); //邮件的发件人
MailMessage mail = new MailMessage();
//设置邮件的标题
mail.Subject = "淘宝会员密码";
//设置邮件的发件人
mail.From = from;
//设置邮件的收件人
string address = username;
string displayName = username.Split('@').FirstOrDefault().ToString();
mail.To.Add(new MailAddress(address, displayName, System.Text.Encoding.UTF8));
/**/
//设置邮件的内容
mail.Body = mailinfo.Body;
//设置邮件的格式
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
//设置邮件的发送级别
mail.Priority = MailPriority.Normal;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;
SmtpClient client = new SmtpClient();
//设置用于 SMTP 事务的主机的名称,填IP地址也可以了
client = new System.Net.Mail.SmtpClient("smtp.ym.163.com");//其它的,列如:smtp.qq.com,smtp.sina.com
//设置用于 SMTP 事务的端口,默认的是 25
client.Port = 25;
client.UseDefaultCredentials = true;
string ss = adminusername.Split('@').FirstOrDefault().ToString();
// client.Credentials = new System.Net.NetworkCredential(ss, adminpwd); //这一行代码会报错,不能去掉@之后语句.
client.Credentials = new System.Net.NetworkCredential(adminusername, adminpwd); //("bianbill@126.com","111")
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.Timeout = 300000;
client.Send(mail);
flag = true;
}
catch (Exception ex)
{
ex.Message.ToString();
}
return flag;
}