Unity发送邮件功能

Posted 丁小未

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity发送邮件功能相关的知识,希望对你有一定的参考价值。

更多精品教程

Aladdin的博客

使用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博客专栏=================

MyBlog:http://blog.csdn.net/dingxiaowei2013 MyQQ:1213250243

Unity QQ群:375151422 cocos2dx QQ群:280818155

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

unity交流群


以上是关于Unity发送邮件功能的主要内容,如果未能解决你的问题,请参考以下文章

如果输入是垃圾邮件,Unity动画属性将保持禁用状态

linux mutt邮件发送配置

Linux:尝试监控不同的 linux 文件系统大小并将邮件发送给 2 人或更多人

Unity游戏开发中的树形结构——红点系统

利用linux mutt 发送邮件(在Shell脚本中使用比较方便)

Exchange Server 2016管理系列课件21.开启邮箱的邮件提示功能