用Unity3D发邮件(带附件),要引用一些必要的类
代码如下:
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 SendEmailTest : MonoBehaviour
{
void OnGUI()
{
if (GUI.Button(new Rect(0, 50, 100, 40), "截图"))
{
Application.CaptureScreenshot("Screen.png");
}
if (GUI.Button(new Rect(0, 0, 100, 40), "发送右键"))
{
SendEmail();
}
}
private void SendEmail()
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("309244655@qq.com");
mail.To.Add("10000@qq.com");
mail.Subject = "题目";
mail.Body = "内容";
mail.Attachments.Add(new Attachment("Screen.png"));
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("309244655@qq.com", "Emailpassword") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(mail);
}
}