截图并且发送到指定邮件

using UnityEngine;

using System.Collections;

using System;
using System.Net;

using System.Net.Mail;

using System.Net.Security;

using System.Security.Cryptography.X509Certificates;


public class SendEmailSrc : MonoBehaviour

{
    
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("1213250243@qq.com");
 
    mail.To.Add("1213250243@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");
   
     smtpServer.Credentials = new System.Net.NetworkCredential("1213250243@qq.com", "密码") as ICredentialsByHost;
       
 smtpServer.EnableSsl = true;
    
    ServicePointManager.ServerCertificateValidationCallback =
 elegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
     
       { return true; };

      
  smtpServer.Send(mail);
   
     Debug.Log("success");
  
  }

 public void GetRete(Camera c,Rect r)
    {
        RenderTexture renderTexture = new RenderTexture((int)r.width,(int)r.height,0);
        c.targetTexture = renderTexture;
        c.Render();

        RenderTexture.active = renderTexture;
        Texture2D texture2D = new Texture2D((int)r.width,(int)r.height, TextureFormat.RGB24,false);
        texture2D.ReadPixels(r,0,0);
        texture2D.Apply();

        c.targetTexture = null;
        RenderTexture.active = null;
        Destroy(renderTexture);

        string path = @"d:\photo-whzq\Screenshot.png";
        byte[] byte1= texture2D.EncodeToPNG();

        File.WriteAllBytes(path, byte1);

        PlayerPrefs.SetString(IMAGEFILE, path);
        string i = PlayerPrefs.GetString(IMAGEFILE);

    }




}

  

posted @ 2019-05-24 10:55  玄~轩逸  阅读(433)  评论(0编辑  收藏  举报