程式碼
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Collections.Generic;
using System.IO;
void SendEmail(){
string acc = "www30506@gmail.com";
string pass = "Crosis2008";
MailMessage Mail = new MailMessage();
Mail.From = new MailAddress(acc);
Mail.To.Add(acc);
Mail.Subject = "[ Subkect ]";
Mail.Body = " content ";
//傳送副檔案
if(!string.IsNullOrEmpty(檔案位置)){
Mail.Attachments.Add(new Attachment(檔案位置));
}
SmtpClient smtpServer = new SmtpClient();
smtpServer.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpServer.Host = "smtp.gmail.com";
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(acc, pass) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ return true; };
smtpServer.Send(Mail);
}
這邊是使用GOOGLE 帳號
如果有被擋下 修正GOOGLE帳號裡面 低安全性應用程式 改成開啟 就能傳送
PS: 如果要使用QQ 去做發送
將 smtpServer.Host = "smtp.gmail.com";
改成 smtpServer.Host = "smtp.qq.com";
再把smtpServer.Port = 587; 刪除
留言列表