Unity SMTP发送电子邮件IOException:连接已关闭

时间:2017-05-25 22:24:24

标签: c# android email unity3d smtp

我试图通过统一发送电子邮件,我的代码如下:

public static void sendLogByEmail(){
            Debug.Log ("Send Log By Email");
            MailMessage mail = new MailMessage();

            mail.From = new MailAddress("mail@gmail.com");
            mail.To.Add("mail@gmail.com");
            mail.Subject = "Log de la " + Session.tipoUsuario + "-" + Session.idTipoUsuario + " de " + PaisesModel.getNombrePais();
            mail.Body = "-" + Session.tipoUsuario + ": " + Session.idTipoUsuario + Environment.NewLine + Environment.NewLine + 
                "-Usuario: " + Session.usuario + Environment.NewLine + Environment.NewLine + 
                    "-Jornada: " + Session.idJornada + Environment.NewLine + Environment.NewLine +
                    "-Dispositivo: " + Session.idDispositivo;

            Attachment data = new Attachment(filePath, System.Net.Mime.MediaTypeNames.Text.Plain);

            System.Net.Mime.ContentDisposition disposition = data.ContentDisposition;
            disposition.CreationDate = System.IO.File.GetCreationTime(filePath);
            disposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath);

            mail.Attachments.Add (data);

            SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
            smtpServer.Port = 465;
            smtpServer.Credentials = new System.Net.NetworkCredential("mail@gmail.com", "password");
            smtpServer.EnableSsl = true;



            ServicePointManager.ServerCertificateValidationCallback =
                delegate(object sim, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors){
                return true;
            };

            try{
                smtpServer.Send (mail);
            } catch (Exception e){
                Debug.Log (e.GetBaseException().ToString());
            }

            mail.Dispose();
        }

我会将电子邮件发送到它发送到的同一地址。就像给自己发电子邮件一样,但我得到以下例外:

System.IO.IOException: Connection closed
  at System.Net.Mail.SmtpClient.Read () [0x00000] in <filename unknown>:0 
  at System.Net.Mail.SmtpClient.SendCore (System.Net.Mail.MailMessage message) [0x00000] in <filename unknown>:0 
  at System.Net.Mail.SmtpClient.SendInternal (System.Net.Mail.MailMessage message) [0x00000] in <filename unknown>:0 
  at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMessage message) [0x00000] in <filename unknown>:0 
UnityEngine.Debug:Log(Object)
Scripts.Controls.LogFileControl:sendLogByEmail() (at Assets/Scripts/Controls/LogFileControl.cs:169)
MyLeftMenuBar:<createProtected>m__30(MyGameObject, EventArgs) (at Assets/Scripts/Controls/MyLeftMenuBar.cs:177)
MyGameObject:OnTap()
InputHandler:handleMouseUp(Vector3)
InputHandler:handleMouseGestures()
InputHandler:Update()

任何人都可以帮助我吗?任何人都知道我是否需要为unity / android / C#安装任何类型的软件,库或插件以便它可以工作?或者我可能缺少任何其他配置(在代码中或在代码之外)?

0 个答案:

没有答案