zoukankan      html  css  js  c++  java
  • C#QQ邮箱验证

    注意:

    QQ邮箱的简单邮件传输协议(SMTP)使用了SSL加密,必须启用SSL加密、指定端口。

    QQ邮箱POP3/SMTP服务默认是关闭的,需要开启服务(设置=>账户=>开启服务)。

    QQ邮箱若有独立密码,需要获取授权码(设置=>账户=>生成授权码)。

    //我们随便写一个注册页面,用QQ邮箱验证完成注册

    //效果图

    //后台代码

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

    public partial class QQYanZheng : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
            MailMessage msg = new MailMessage();  //生成一个关于邮箱的类

            msg.To.Add(TextBox1.Text.Trim());   //文本框里的QQ邮箱  (即注册人的邮箱)
            msg.CC.Add(TextBox1.Text.Trim());   //上同

            msg.From = new MailAddress("1******55.qq.com", "登录验证");   //第一个是发送验证码的QQ  第二个参数是发送的标题

            msg.Subject = "登录验证";
            //标题格式为UTF8格式
            msg.SubjectEncoding = Encoding.UTF8;

           //随机生成6位验证码

            ArrayList MyArray = new ArrayList();
           Random random = new Random();
           string str = null;
           int Nums = 6;
            while (Nums > 0)
           {
              int i = random.Next(1, 9);
            if (MyArray.Count < 6)
          {
              MyArray.Add(i);
          }
             Nums -= 1;
         }
            for (int j = 0; j <= MyArray.Count - 1; j++)
         {
           str += MyArray[j].ToString();
        }
       msg.Body = str;  //str为6位随机数
       //内容格式为UTF8格式
       msg.BodyEncoding = Encoding.UTF8;

        SmtpClient client = new SmtpClient();
       //SMTP服务器地址
       client.Host = "smtp.qq.com";
       //SMTP端口,QQ邮箱填写587
       client.Port = 587;
       //启用SSL加密
      client.EnableSsl = true;

       client.Credentials = new NetworkCredential("1*****55@qq.com", "fnjnf***");    //第一个参数为发送验证码的QQ邮箱     第二个参数为  发送验证码QQ邮箱的授权码  
       //发送邮件
       client.Send(msg);
     }
    }

    具体QQ邮箱授权码的生成步骤可以百度参考



  • 相关阅读:
    支持向量机SVM知识点概括
    决策树知识点概括
    HDU 3081 Marriage Match II
    HDU 3572 Task Schedule
    HDU 4888 Redraw Beautiful Drawings
    Poj 2728 Desert King
    HDU 3926 Hand in Hand
    HDU 1598 find the most comfortable road
    HDU 4393 Throw nails
    POJ 1486 Sorting Slides
  • 原文地址:https://www.cnblogs.com/YangWenStudent/p/8259779.html
Copyright © 2011-2022 走看看