最近一个项目,要实现注册的时候同时发送一个邮件到注册人的邮箱,通过发送的邮箱链接来激活帐号,发送邮件实现如下:
//第一个参数如果是163邮箱就写smtp.163.com
//第二个参数发件人的帐号
//第三个参数发件人密码
//第四个参数收件人帐号
//第五个参数主题
//第六个参数内容
public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string strSubject, string strBody)
{
System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
client.UseDefaultCredentials = false;
client.Credentials =
new System.Net.NetworkCredential(strFrom, strFromPass);
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message =
new MailMessage(strFrom, strto, strSubject, strBody);
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
client.Send(message);
}
发链接是一般发送一个类似于这样的:
http://www.xx.com/xxx.aspx?sdfoiuwe542u594rweorjdfklsjdriouew90r
而这个sdfoiuwe542u594rweorjdfklsjdriouew90r就是根据某些特别的字符加密的的东西,只要你服务器能识别出来(解密出来),就说明人家是通过邮箱进行激活的,至少第一次是这样的,当然可以把时间段加密在里面,这样过了某个时间段后就可以不进行任何操作,直接返回你想返回的信息,这样就能实现账户激活了!