我需要在 Unity3D 中使用 C# 发送电子邮件。我已经这样做了,但是遇到了运行时警告。请帮我解决以下警告。
警告:在名为“Program”的脚本文件中定义的类不是从 MonoBehaviour 或 ScriptableObject 派生的
我的代码是:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
namespace EMail
{
class Program
{
static void Main(string[] args)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient smtpC = new SmtpClient("smtp.gmail.com");
//From address to send email
mail.From = new MailAddress("From@gmail.com");
//To address to send email
mail.To.Add("To@gmail.com");
mail.Body = "This is a test mail from C# program";
mail.Subject = "TEST";
smtpC.Port = 587;
//Credentials for From address
smtpC.Credentials =(System.Net.ICredentialsByHost) new System.Net.NetworkCredential("EmailID", "password");
smtpC.EnableSsl = true;
smtpC.Send(mail);
Console.WriteLine("Message sent successfully");
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.GetBaseException());
Console.ReadLine();
}
}
}
}