18 Star 28 Fork 11

丁小未 / CSharpSendEmail

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

#使用Unity发送邮件案例

案例效果图

这里写图片描述 这里写图片描述 发送之后立马收到邮件 收到的邮件

代码

CS控制台

说明:单纯的发送邮件

class Program
	{
		static void Main(string[] args)
		{
			SmtpClient mailClient = new SmtpClient("smtp.qq.com");
			mailClient.EnableSsl = true;
			//Credentials登陆SMTP服务器的身份验证.
			mailClient.Credentials = new NetworkCredential("1213250243@qq.com", "");
			//test@qq.com发件人地址、test@tom.com收件人地址
			MailMessage message = new MailMessage(new MailAddress("1213250243@qq.com"), new MailAddress("aladdingame@qq.com"));

			// message.Bcc.Add(new MailAddress("tst@qq.com")); //可以添加多个收件人
			message.Body = "Hello Word!";//邮件内容
			message.Subject = "this is a test";//邮件主题
			//Attachment 附件
			Attachment att = new Attachment(@"D:/test.mp3");
			message.Attachments.Add(att);//添加附件
			Console.WriteLine("Start Send Mail....");
			//发送....
			mailClient.Send(message);

			Console.WriteLine("Send Mail Successed");

			Console.ReadLine();
		}
	}

Unity

说明:截图并且发送到指定邮件

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 =
			delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
			{ return true; };

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

欢迎查看我的博客


欢迎关注我的围脖

==================== 迂者 丁小未 CSDN博客专栏=================

我的QQ:1213250243 Unity QQ群:375151422

====================== 相互学习,共同进步 ===================

空文件

简介

C#发送邮件 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C#
1
https://gitee.com/dingxiaowei/CSharpSendEmail.git
git@gitee.com:dingxiaowei/CSharpSendEmail.git
dingxiaowei
CSharpSendEmail
CSharpSendEmail
master

搜索帮助