【UnityTools】在Unity中使用邮箱发送邮件

发邮件是一个非常简单方便的功能,通常可以用在给开发者提醒相关的功能上,如游戏内的反馈建议,因为C#已经封装好了相关模块,只需要简单调用即可。

下面以qq邮箱为例:

需要准备一个邮箱,用来发送邮件,并且开启邮箱设置中的SMTP服务,并记下SMTP密码。

然后用以下方法即可给开发者发送邮件:

public static void SendEmail(string title, string text)
	{
		MailMessage mail = new MailMessage();

// 发送方邮箱
		mail.From = new MailAddress("发送方邮箱@qq.com");
		mail.To.Add("zeng123m@qq.com");
		mail.Subject = title;
		mail.Body = text;

//邮箱信息,邮箱需开通smtp功能
		SmtpClient smtpServer = new SmtpClient("smtp.qq.com");
		smtpServer.Credentials = new System.Net.NetworkCredential("发送方邮箱@qq.com", SMTP密码) as ICredentialsByHost;
		smtpServer.EnableSsl = true;
		ServicePointManager.ServerCertificateValidationCallback =
			delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
			{ return true; };
		smtpServer.Send(mail);
		Debug.Log("send email success");
	}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注