Unity 发送邮件(附 QQ邮箱开启Smtp授权方法)

增加个说明哈,发布后失败,如果实现,欢迎骚扰 

namespace LastZero.Utility
{
    /// 
    /// 邮件控制类
    /// 
    public static class EmailController {

        //发件服务器邮箱配置,请自行替换
        private const string myEmail = "";//邮箱地址
        private const string myPwd = "";//授权码

        /// 
        /// 发送邮件
        /// 
        /// 收件人
        /// 主题
        /// 内容
        public static void SendMail(List receivers,string subject, string body)
        {
            MailMessage message = new MailMessage();
            message.From = new MailAddress(myEmail);//设置发件地址
            receivers.ForEach(receiver => message.To.Add(receiver));//添加收件人

            //设置标题和内容  及其格式
            message.Subject = subject;
            message.Body = body;
            message.SubjectEncoding = Encoding.UTF8;
            message.BodyEncoding = Encoding.UTF8;

            //设置发件服务器
            SmtpClient client = new SmtpClient("smtp.qq.com");
            client.Credentials = new NetworkCredential(myEmail, myPwd) as ICredentialsByHost;

            client.SendCompleted += Client_SendCompleted;//异常
            client.Send(message);//发送消息
        }

        /// 
        /// 异常
        /// 
        /// 
        /// 
        private static void Client_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
            bool result = e.Error == null;

            if (!result)
            {
                Debug.LogError(e.Error);
            }
        }
    }
}

QQ邮箱开启Smtp授权:

1、打开邮箱,点击设置

2、点击账户

3、点击开启

Unity 发送邮件(附 QQ邮箱开启Smtp授权方法)_第1张图片

4、短信验证,开启服务,记下授权码

你可能感兴趣的:(Unity3D)