如何用unity3d实现发送带附件的邮件
2024-08-24 14:40:05
以Gmail为例。
点击屏幕的Capture按钮得到当前屏幕截图,点击Send按钮将之前的截图作为附件发送邮件。
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 TryDemo : MonoBehaviour { // Use this for initialization
void Start () { } // Update is called once per frame
void Update () { } void OnGUI() {
if (GUI.Button(new Rect(, , , ), "Capture")) {
Debug.Log("Capture Screenshot");
Application.CaptureScreenshot("screen.png");
}
if (GUI.Button(new Rect(, , , ), "Send")) {
SendEmail();
}
} private void SendEmail()
{
MailMessage mail = new MailMessage(); mail.From = new MailAddress("youraddress@gmail.com");
mail.To.Add("youraddress@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.gmail.com");
smtpServer.Port = ;
smtpServer.Credentials = new System.Net.NetworkCredential("youraddress@gmail.com", "yourpassword")as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; }; smtpServer.Send(mail);
Debug.Log("success");
}
}
①Application.RegisterLogCallback(OnDebugCallBackHandler);可以给debug的打印加入回调函数,监听每次的打印,通过这个来判断是否有出错日志并作出反应
②基本的发送错误日志方法就是通过邮件发送,可以通过在unity中用c#脚本来发送邮件,具体方法在上文有提到;也可以通过Process.Start(“name.exe”)来调用外部程序发送日志邮件,具体操作可以百度c编程发送邮件,有很多例子。
③用c#脚本发送邮件日志更方便实现,c#提供了邮件发送功能的封装。另外还可以用Application.CaptureScreenshot(“filename”)来保存截图用于发送,提供错误时程序截图。
最新文章
- [转]抓取安卓APP内接口的方法--Charles
- 轻量级应用开发之(02)UIView
- 《verilog数字系统设计教程》书评
- POJ 3177 Redundant Paths(Tarjan)
- 小白日记3:kali渗透测试之被动信息收集(二)-dig、whios、dnsenum、fierce
- Bzoj-2820 YY的GCD Mobius反演,分块
- OS开发网络篇—监测网络状态
- C#操作Excel总结
- 我的Python成长之路---第三天---Python基础(12)---2016年1月16日(雾霾)
- 设置控件Enable=false,控件颜色不变
- 使用 dom4j 处理 xml (2)
- hadoop day 7
- [ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.5.0-rc1:compile (default) on project zeus-web: Command 解决
- [OpenCV] Samples 18: Load image and check its attributes
- js - 如何使子元素阻止继承父元素事件
- 《MinDoc 接口文档在线管理系统》
- 向大家推荐一个在.Net下使用C#语言和Managed DirectX 9开发游戏的视频教程
- 封装一个统一返回json结果类JsonResult
- 0702-spring cloud config-git仓库配置、用户授权
- Linux网络编程案例分析
热门文章
- AJAX同步和异步的区别
- 算法模板——sap网络最大流 3(递归+邻接矩阵)
- java深拷贝和浅拷贝
- TypeScript设计模式之中介者、观察者
- T——SQL基础语句(定义变量,赋值,取值,分支,循环,存储过程)
- Apache无法启动原因
- js提交表单错误:document.form.submit() is not a function
- vs打开项目出错:未找到导入的项目“C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\BuildCustomizations\CUDA 5.0.props”的解决办法
- 【一】Swift 3.0 新浪微博项目实战 -整体框架搭建
- iOS开发之数据存储之Core Data