void Sending()
{
Debug.Log(“开始发送邮件”);
MailMessage mail = new MailMessage();
mail.From = new MailAddress(“邮箱账号@qq.com”);//写上发送端邮箱账号
mail.To.Add(input.text);
mail.Subject = “标题”;//发送出去的邮件标题
mail.Body = “请查收附件”;//发送出去的邮件内容文本
mail.Attachments.Add(new Attachment(path));
SmtpClient smtpServer = new SmtpClient("smtp.qq.com");//不用改
smtpServer.EnableSsl = true;
smtpServer.UseDefaultCredentials = false;
smtpServer.Port = 587;//不用改
smtpServer.Credentials = new System.Net.NetworkCredential("邮箱账号@qq.com", "授权码") as ICredentialsByHost; //发送端邮箱账号和在邮箱获取到的授权码
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate X509Certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
try
{
smtpServer.Send(mail);
}
catch (System.Exception e)
{
throw;
}
Debug.Log("发送成功");
smtpServer = null; // 发送完毕 初始化
}