C# Unity SMTP发送电子邮件IOException:连接已关闭
我正在尝试通过unity发送电子邮件,我的代码如下:C# Unity SMTP发送电子邮件IOException:连接已关闭,c#,android,email,unity3d,smtp,C#,Android,Email,Unity3d,Smtp,我正在尝试通过unity发送电子邮件,我的代码如下: 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@g
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()
System.IO.IOException:连接已关闭
在System.Net.Mail.SmtpClient.Read()[0x00000]中:0
位于:0中的System.Net.Mail.SmtpClient.SendCore(System.Net.Mail.MailMessage消息)[0x00000]处
位于:0中的System.Net.Mail.SmtpClient.SendInternal(System.Net.Mail.MailMessage消息)[0x00000]处
在:0中的System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMessage消息)[0x00000]处
调试:日志(对象)
Scripts.Controls.LogFileControl:sendLogByEmail()(位于Assets/Scripts/Controls/LogFileControl.cs:169)
MyLeftMenuBar:m_uu30(MyGameObject,EventArgs)(位于Assets/Scripts/Controls/MyLeftMenuBar.cs:177)
MyGameObject:OnTap()
输入处理器:handleMouseUp(矢量3)
InPuthHandler:HandleMouseSpiress()
inputhHandler:Update()
有人能帮我吗?有人知道我是否需要为unity/android/C安装任何类型的软件、库或插件才能正常工作吗?或者我可能缺少的任何其他配置(代码内或代码外)?允许gmail服务器与您的应用程序配合使用。请参阅post。@程序员仍然遇到相同的错误,请尝试其他电子邮件服务,看看它是否有效。如果没有附件,会发生什么情况?这个房间有多大attachment@AdamVincent第一条评论中包含了不太安全的应用程序。访问Google API可能需要oAuth,但SMTP是一种协议。Google接受自90年代以来就存在的接受SASL凭证的SMTP/IMAP协议,并将其扩展为允许oAuth作为替代方案。参考: