unity给用户发邮件

用户忘记了密码,找回密码时候:需要把服务器记录的密码发送给用户,这个功能是服务器来做还是客户端来做好呢。

我个人是客户端,和服务器不在一起,尽量少麻烦人家。决定自己拿到服务器密码后客户端发送给用户。肯定没有服务器发送

安全些。

using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;

public class ForgetPassWord : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public static void sendPassWordToEmail(string password)

    {
       SmtpClient mailClient = new SmtpClient("smtp.qq.com");
        mailClient.EnableSsl = true;
        //Credentials登陆SMTP服务器的身份验证.


        mailClient.Credentials = new NetworkCredential("2398112@qq.com", "hcrlxbrzwhynebdg") as ICredentialsByHost;
        //test@qq.com发件人地址、[url=mailto:test@tom.com]test@tom.com[/url]收件人地址
        MailMessage message = new MailMessage(new MailAddress("2398112668@qq.com"), new MailAddress("13300624@qq.com"));

        // message.Bcc.Add(new MailAddress("tst@qq.com")); //可以添加多个收件人
        message.Body = "找回密码";
        message.Subject = "您的密码是:" + password;
        
        Attachment att = new Attachment(@"E:/cat2.png");
        message.Attachments.Add(att);//添加附件
        Debug.Log("Start Send Mail....");

        ServicePointManager.ServerCertificateValidationCallback =
            delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            { return true; };
        //发送....
        mailClient.Send(message);
        Debug.Log("Send Mail Successed");
    }
}
//这里以QQ邮箱为例子NetworkCredential("2398112@qq.com", "hcrlxbrzwhynebdg")

//进入QQ邮箱,开通相应的服务。

最后验证完成会受到一个密码:

将这个密码写到NetworkCredential("2398112@qq.com", "hcrlxbrzwhynebdg")

这样子用户就实现该功能了

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值