unity游戏 如何发送邮件

第一:需要开通邮箱的 smtp 服务

开通后就会有个  让你设置  密码 

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 MailSend : MonoBehaviour
{

 private void SendEmail()
    {
        MailMessage mail = new MailMessage();

        mail.From = new MailAddress("[email protected]");
        mail.To.Add("[email protected]");
 

        mail.Subject = "坚持了";
        mail.Body = "你这个很牛逼...   "+ timess;

        SmtpClient smtpServer = new SmtpClient("smtp.126.com");

// 这里的密码就是你刚才设置的密码
        smtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "密码") as ICredentialsByHost;
        smtpServer.EnableSsl = true;
        ServicePointManager.ServerCertificateValidationCallback =
            delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            { return true; };

        smtpServer.Send(mail);
        Debug.Log("success");
    }

 void OnGUI()
    {

        if (GUI.Button(new Rect(100, 1000, 100, 60), "Send"))
        {
            SendEmail();
        }
    }

}