纳金网

标题: Unity 中发送邮件的代码 [打印本页]

作者: 烟雨    时间: 2015-5-28 01:05
标题: Unity 中发送邮件的代码
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using System.Net.Mail;
  5. using System.Net;
  6. using System;
  7. public class SendMail : MonoBehaviour {
  8.     public InputField Title;
  9.     public InputField Countent;
  10.     public Button Send;
  11.     public Text Show;

  12.     public void Message()
  13.     {
  14.         try
  15.         {
  16.             MailMessage mailMsg = new MailMessage();
  17.             mailMsg.From = new MailAddress("要发送邮件的邮箱", "名字(这里可以随意)");
  18.             mailMsg.To.Add(new MailAddress("对方的邮箱(接收方的邮箱可以是QQ。163等等 )", "对方邮箱的名字(随意。。。。。)"));
  19.             mailMsg.Subject =Title.text;
  20.             mailMsg.Body = Countent.text;
  21.             SmtpClient client = new SmtpClient("smtp.163.com",25);  //发送服务器
  22.             client.Credentials = (ICredentialsByHost)new NetworkCredential("需要发送邮件的邮箱", "邮箱的密码");
  23.             client.Send(mailMsg);
  24.             Debug.Log("OK");
  25.             Show.text = "发送成功~~~~~~~~~~~~~~~";
  26.         }
  27.         catch (Exception ex)
  28.         {
  29.             
  30.             Show.text=("异常"+ex.StackTrace);
  31.         }
  32.     }
  33. }
复制代码





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5