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("[email protected]");//发送邮件的邮箱号;
mail.To.Add("[email protected]");//接受邮件的邮箱号
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("[email protected]", " 授权码") 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不支持)