Unity中使用QQ邮箱发送验证码

1.打开邮箱设置开启POP3/SMTP服务

2.生成授权码

3.发送验证码按钮事件

public void SendVerificationCode()
{
        // 随机生成验证码
        VerificationCode = UnityEngine.Random.Range(11219, 96719);
        // 保存到本地
        PlayerPrefs.SetInt("VerificationCode", VerificationCode);
        SmtpClient mailClient = new SmtpClient("smtp.qq.com");
        mailClient.EnableSsl = true;
        // 登陆SMTP服务器进行身份验证
        mailClient.Credentials = new NetworkCredential("[email protected]", "授权码");
        // [email protected]发件人地址、[email protected]收件人地址
        MailMessage message = new MailMessage(new MailAddress("[email protected]"),new MailAddress("[email protected]"));//收件
        // 可添加多个收件人
        //message.Bcc.Add(new MailAddress("[email protected]")); 
        // 邮件内容
        message.Body = "验证码:" + PlayerPrefs.GetInt("VerificationCode");
        // 邮件主题
        message.Subject = "验证码";                              
        // 发送
        mailClient.Send(message);
}

猜你喜欢

转载自blog.csdn.net/Test_Two/article/details/122325966