我正在使用unity,将带有屏幕截图的电子邮件发送到我的电子邮箱, 它与调试器完美配合,但是,当我构建独立的时候,它无论如何都不起作用...... 继承我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using System.IO;
using System.Collections;
using UnityEngine;
using System.Collections;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class Tabela : MonoBehaviour
{
public void OnGUI()
{
{
StartCoroutine(ScreenshotEncode());
}
}
IEnumerator ScreenshotEncode()
{
// We should only read the screen after all rendering is complete
yield return new WaitForEndOfFrame();
// Create a texture the size of the screen, RGB24 format
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D( width, height, TextureFormat.RGB24, false );
// Read screen contents into the texture
tex.ReadPixels(new Rect(0, 0, width, height), 0, 0 );
tex.Apply();
// Encode texture into PNG
byte[] bytes = tex.EncodeToPNG();
// save our test image (could also upload to WWW)
File.WriteAllBytes(Application.dataPath + "/../test-" + count + ".png", bytes);
// count++;
DestroyObject(tex);
Debug.Log(Application.dataPath + "/../test-" + count + ".png");
MailMessage mail = new MailMessage();
mail.From = new MailAddress("myemail@gmail.com");
mail.To.Add("myemail@gmail.com");
mail.Subject = "Teste ";
mail.Body = "test";
mail.Attachments.Add(new Attachment(Application.dataPath + "/../test-" + count + ".png",
@"image/png"));
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("myemail@gmail.com", "password") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
smtpServer.Send(mail);
Debug.Log("success");
status = "ok";
}
}
/ ===============编辑=========== 得到了一些错误:
smtpexception: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257g26sm76791788yhk.3 - gsmtp
答案 0 :(得分:3)
解决方案是播放器设置 - >其他设置 - > api兼容级别 - > .NET 2.0
答案 1 :(得分:0)
根据您的错误,smtp客户端(gmail)未授权从不安全的应用程序发送它,解决这个问题,可以为您用来发送邮件的Gmail帐户提供安全性较低的应用程序。