Unity 跨平台发送

来源:互联网 发布:一元购平台源码 编辑:程序博客网 时间:2024/06/03 23:39

公司项目需求要求将客户的问题反馈发送到公司邮箱中,在网上查询后发现需要修改一些地方;

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


public class Text1 : MonoBehaviour
{
    public Text t;
    void OnGUI()
    {
        if (GUI.Button(new Rect(0, 50, 100, 40), "Capture"))
        {
            Debug.Log("Capture Screenshot");
            Application.CaptureScreenshot("screen.png");
        }
        if (GUI.Button(new Rect(0, 0, 100, 40), "Send"))
        {
            SendEmail();
        }
    }


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


        mail.From = new MailAddress("1245651651@qq.com");//发送邮件的邮箱号;
        mail.To.Add("1245651651@qq.com");//接受邮件的邮箱号
        mail.Subject = "Test Mail";//邮件标题
        mail.Body = "This is for testing SMTP mail from GMAIL";//邮件内容
        mail.Attachments.Add(new Attachment("screen.png"));//添加附件


        SmtpClient smtpServer = new SmtpClient("smtp.qq.com");//选择服务器这里是qq
        smtpServer.Credentials = new System.Net.NetworkCredential("1245651651@qq.com", " 授权码") as ICredentialsByHost;//这里面的授权码是需要去邮箱中设置的,详细设置见下图




        smtpServer.EnableSsl = true;
        ServicePointManager.ServerCertificateValidationCallback =
            delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            { return true; };    
        try
        {
            smtpServer.Send(mail);//发送邮件
            t.text = "Succeres";
        }
        catch(Exception)
        {
            Exception e=new Exception();
            t.text = e.Message;
            
        }
        
    }
}

如果需要在手机品台上发送邮件,

需要注意的是在playersetting中需要设置api level 为.net2.0 (.net2.0 subset不支持)