通过邮箱进行注册验证

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;

namespace EmailTest
{
    public partial class Email : System.Web.UI.Page
    {
        private string _strSmtpServer = "";
        private string _strFrom = "";
        private string _strFromPass = "";
        private string _strto = "";
        private string _strSubject = "";
        private string _strBody = "";
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        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 = false;
            client.Send(message);
        }
        //第一个参数如果是163邮箱就写smtp.163.com
        //第二个参数发件人的帐号
        //第三个参数发件人密码
        //第四个参数收件人帐号
        //第五个参数主题
        //第六个参数内容.

        protected void Button1_Click(object sender, EventArgs e)
        {
             _strSmtpServer = "smtp.163.com";
             _strFrom = "yulone2012@163.com";
             _strFromPass = "xxxxxx";
             _strto = "1154119178@qq.com";
             _strSubject = "注册";
             _strBody = "你好!";
             SendSMTPEMail(_strSmtpServer, _strFrom, _strFromPass, _strto, _strSubject, _strBody);
             Response.Write("<script>alert('成功');</script>");

        }
 
    }
}

posted @ 2012-09-13 16:33  yuloe2012  阅读(169)  评论(0编辑  收藏  举报