读书人

怎么实现到邮箱激活这个功能

发布时间: 2012-03-27 13:44:24 作者: rapoo

如何实现到邮箱激活这个功能
我刚做了一个网站,想实现在用户注册成功后发一个超链到用户邮箱,用户点击超链到此网站以便激活帐号!我是初学者,请各位前辈帮忙啊!先谢了!

[解决办法]
ContentType = "text/html";
public void MailSend(string MailFrom,string MailTo,string MailPwd,string Mailtitle,string MailCon)
{
MailMessage MyMail = new MailMessage();
MyMail.From = new MailAddress("", "");
MyMail.To.Add(new MailAddress(""));
MyMail.Subject = Mailtitle;
MyMail.Body = MailCon;
MyMail.IsBodyHtml = true;
SmtpClient smtpclient = new SmtpClient();
smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpclient.Host = "";
smtpclient.Credentials = new System.Net.NetworkCredential(MailFrom, MailPwd);
smtpclient.Send(MyMail);
}

[解决办法]
邮箱发送很简单,用户注册之后 发送Url到用户的邮箱,
将url的参数加密。 然后再指定的页面获取 url参数,解密 ,匹配成功 ---》激活成
[解决办法]
发送邮件的程序
上面的思路已经说的很清楚了~我就不多说了

C# code
using System;using System.Collections.Generic;using System.Net.Sockets;using System.Text;using System.Net.Mail;using System.Threading;namespace mail{    class Program    {        static void Main(string[] args)        {            SendMailUseGmail();            Console.ReadLine();        }        public static void SendMailUseGmail()        {            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();            msg.From = new MailAddress("XXXXX@163.com", "foolfire", System.Text.Encoding.UTF8); //发件人地址(可以随便写),发件人姓名,编码*/             msg.Subject = "give your some emails by foolfire1";//邮件标题             msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码             msg.Body = "sdaaaaaaaaaaaaaaaaa";//邮件内容             msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码             msg.IsBodyHtml = false;//是否是HTML邮件             msg.Priority = MailPriority.High;//邮件优先级             SmtpClient client = new SmtpClient();            //发件邮箱和密码 ,注意这里要与发件人地址的邮箱一致            client.Credentials = new System.Net.NetworkCredential("XXXXX@163.com", "XXXXXXXXX");             //client.Port = 25;//Gmail使用的端口587             //client.EnableSsl = true;//经过ssl加密            client.DeliveryMethod = SmtpDeliveryMethod.Network;            client.Host = "smtp.163.com";            object userState = msg;            //这里可以随便写什么,只要是规范的email地址            msg.To.Add("XXXXXX@tom.com");            try            {                /***************************/                /*请注意SmtpClient类还有两个用于发送Email的方法:                 * Send()和SendAsync()。Send()方法在它的发送操作完成前阻塞其它的程序执行;                 * SendAsync()方法异步地发送Email。                 * 不像Send()方法,SendAsync()方法不必等待检测发送操作是否成功。*/                /***************************/                //client.SendAsync(msg, userState);                ////client.Send(msg);                //Console.WriteLine("success!");                System.Threading.Thread.Sleep(100);                client.Send(msg);                Console.WriteLine("发送成功!");            }            catch (System.Net.Mail.SmtpException ex)            {                Console.WriteLine(ex.StackTrace);            }        }    }} 

读书人网 >C#

热点推荐