zoukankan      html  css  js  c++  java
  • 项目的登录注册如何用邮箱发送验证码

    这里用QQ邮箱做样例

    点击设置,点击账户,往下滑
    在这里插入图片描述

    把这里全都打开,然后一会下面代码中的授权码,就是这个页面中的生成授权码
    在这里插入图片描述

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Mail;
    using System.Net.Mime;
    using System.Web;
    
    namespace youxiangyanzhneg
    {
        public class SendQQEmail
        {
            //实例化一个发送邮件类。
            private static MailMessage mailMessage = new MailMessage();
            public static bool QQ_email()
            {
                //发件人邮箱地址,方法重载不同,可以根据需求自行选择。
                mailMessage.From = new MailAddress("发件人邮箱", "发件人的名称");
                //收件人邮箱地址。
                mailMessage.To.Add(new MailAddress("收件人邮箱"));
                //邮件标题。
                mailMessage.Subject = "邮箱验证码";
                //邮件内容。
                mailMessage.Body = "验证码为:123456";
                //添加到附件中   这里的附件,每个附件之间使用  ,  分开
                AddAnnex($"D:/Android文件/1e9d9bbf-595b-49ed-bbbf-1e2a1e48c79e.png");
    
                //实例化一个SmtpClient类。
                SmtpClient client = new SmtpClient();
                //在这里我使用的是qq邮箱,所以是smtp.qq.com,如果你使用的是126邮箱,那么就是smtp.126.com。
                client.Host = "smtp.qq.com";
                //使用安全加密连接。
                client.EnableSsl = true;
                //不和请求一块发送。
                client.UseDefaultCredentials = false;
                //验证发件人身份(发件人的邮箱,邮箱里的生成授权码);
                client.Credentials = new NetworkCredential("发件人的邮箱", "邮箱的授权码");
                //发送
                client.Send(mailMessage);
                return true;
            }
    
    
            private static void AddAnnex(string Path)
            {
                string[] path = Path.Split(',');
                Attachment data;
                ContentDisposition disposition;
                for (int i = 0; i < path.Length; i++)
                {
                    data = new Attachment(path[i], MediaTypeNames.Application.Octet);//实例化附件 
                    disposition = data.ContentDisposition;
                    disposition.CreationDate = System.IO.File.GetCreationTime(path[i]);//获取附件的创建日期 
                    disposition.ModificationDate = System.IO.File.GetLastWriteTime(path[i]);//获取附件的修改日期 
                    disposition.ReadDate = System.IO.File.GetLastAccessTime(path[i]);//获取附件的读取日期 
                    mailMessage.Attachments.Add(data);//添加到附件中 
                }
            }
    
        }  
    }
    

    然后使用代码直接调用

      SendQQEmail.QQ_email();
    

    运行的效果图
    在这里插入图片描述

  • 相关阅读:
    走进DOM:HTML DOM
    iOS 去掉UITableView风格为group时候的最顶部的空白距离
    Codeforces 394D Physical Education and Buns 胡搞
    查询出每一个雇员的姓名,工资,部门名称,工资在公司的等级及其领导的姓名,领导的工资,以及领导所相应的等级
    CCBAnimationManager
    sendto 和 recvfrom 函数
    三张图让你高速明确activity与fragment生命周期的异同点
    EWS 流通知订阅邮件
    [EWS]如何: 通过使用 Exchange 中的 EWS 流有关邮箱事件的通知
    async、await正确姿势
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13074371.html
Copyright © 2011-2022 走看看