Unity 跨平台发送

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

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不支持)


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值