在Unity中发送邮件带图片的三种方式(C#脚本)(同时发多.doc_第1页
在Unity中发送邮件带图片的三种方式(C#脚本)(同时发多.doc_第2页
在Unity中发送邮件带图片的三种方式(C#脚本)(同时发多.doc_第3页
在Unity中发送邮件带图片的三种方式(C#脚本)(同时发多.doc_第4页
在Unity中发送邮件带图片的三种方式(C#脚本)(同时发多.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

在Unity中发送邮件带图片的三种方式(C#脚本)(同时发多人不同邮件)1,在正文中插入图片发送usingUnityEngine;usingSystem.Collections;usingSystem.Net.Mail;usingSystem.Net;usingSystem;usingSystem.IO;publicclass SendMessage : MonoBehaviour string path =; / Use this for initialization void Start () / Update is called once per frame void Update () void OnMouseDown() stringreceiverName =receiverName; stringreceiverEmail =receiverEmail; stringsenderName =senderName; stringsenderEmail =senderEmail; path =Application.dataPath +/test.png; /截屏存储路径 Application.CaptureScreenshot(path); Debug.Log(path); /函数调用 SendEmail(receiverName,receiverEmail,senderName,senderEmail); publicvoid SendEmail(stringreceiverName,string receiverEmail,string senderName,string senderEmail) MailMessage mail= new MailMessage(); mail.From = new MailAddress(senderEmail); mail.To.Add(receiverEmail); mail.Subject = 标题; string htmlBody =文本文字; /传参 htmlBody += receiverName; htmlBody +=    ; htmlBody +=; /first we create the Plain Text partAlternateView plainView =AlternateView.CreateAlternateViewFromString(This is my plain text content, viewable by thoseclients that dont support html, null, text/plain); AlternateView htmlView =AlternateView.CreateAlternateViewFromString(htmlBody, null, text/html); /createthe LinkedResource (embedded image) LinkedResource picture = new LinkedResource(Application.dataPath+/test.png); picture.ContentId= companylogo; /add the LinkedResource to the appropriateview htmlView.LinkedResources.Add(picture); /add the views mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView); SmtpClient client = newSmtpClient(); /specify the mail server address client.UseDefaultCredentials = false;client.Credentials = (ICredentialsByHost)new System.Net.NetworkCredential(senderEmail, password);client.DeliveryMethod = SmtpDeliveryMethod.Network;client.Send(mail); 2,以附件形式发送 using UnityEngine; using System.Collections; using System.Net.Mail; using System.Net; using System; using System.IO; publicclass SendMessage : MonoBehaviour publicstring path =; / Use this for initialization void Start () / Update is called once per frame void Update () void OnMouseDown() string customerName1 =receiverName; string customerEmail1 =receiverEmail; string saleaName1 =senderName; string salesEmail1=senderEmail; path =Application.dataPath +/test.png; /截屏函数 Application.CaptureScreenshot(path); Debug.Log(path); /函数调用 SendEmail(customerName1,customerEmail1,saleaName1,salesEmail1); publicvoid SendEmail(stringcustomerName,string customerEmail,stringsalesName,string salesEmail) System.Net.Mail.SmtpClientclient = new SmtpClient(); client.UseDefaultCredentials= false; client.Credentials= (ICredentialsByHost)new System.Net.NetworkCredential(salesEmail, password); client.DeliveryMethod= SmtpDeliveryMethod.Network; MailAddressaddressFrom = new MailAddress(salesEmail, salesName); MailAddressaddressTo = new MailAddress(customerEmail, customerName); System.Net.Mail.MailMessagemessage = new MailMessage(addressFrom, addressTo); message.Sender= new MailAddress(salesEmail); message.BodyEncoding= System.Text.Encoding.UTF8; message.IsBodyHtml= true; string mailBody = ; message.Body = mailBody; message.Subject= This is a test; message.Attachments.Add( new Attachment(Application.dataPath +/test.png ); message.Attachments0.ContentId=ewen; message.Attachments0.ContentType.Name=

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论