kUr*_*4m4 5 c# android smtp unity-game-engine
我正在尝试使用SmtpClient类从智能手机内部发送一封电子邮件.我已经在iOS上完成了这个非常简单的任务,但完全相同的代码在android上不起作用.这是代码:
private IEnumerator sendAutoMail (string textBody,string title)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(sender);
mail.To.Add(receiver);
mail.Subject = "R4UL " + title;
mail.Body = textBody;
Debug.Log("Connecting to SMTP server");
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(sender, password) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
Debug.Log("Sending message");
smtpServer.Send(mail);
yield return null;
}
Run Code Online (Sandbox Code Playgroud)
发件人,密码和收件人是我的Gmail帐户,我的Gmail密码和我希望分别发送电子邮件的人.
所以这在iOS上完美运行但在Android上引发了以下错误:
I/Unity(6256):SocketException:没有这样的主机是I/Unity(6256):在System.Net.Dns.GetHostByName(System.String hostName)[0 x00000] in:0 I/Unity(6256):at System.Net.Dns.GetHostEntry(System.String hostNameOrAdd ress)[0x00000] in:0 I/Unity(6256):at System.Net.Dns.GetHostAddresses(System.String hostNameO rAddress)[0x00000] in:0 I/Unity(6256):在System.Net.Sockets.TcpClient.Connect(System.String主机名,Int32端口)[0x00000] in:0 I/Unity(6256):at System.Net.Sockets.TcpClient..ctor( System.String hostna me,Int32 port)[0x00000] in:0 I/Unity(6256):at System.Net.Mail.SmtpClient.SendInternal(System.Net.Mail .MailMessage message)[0x00000] in:0 I/Unity(6256):在System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMes sage message)[0x00000] in:0 I/Unity(6256):Rethrow as SmtpException:无法发送消息.I/Unity(6256):在System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMes sage message)[0x00000] in:0 I/Unity(6256):在FeedbackSender + c__Iterator1.MoveNext()
我设法在线上找到错误位置: smtpServer.Send(mail);
关于可能导致这个问题的任何想法?我有Android和iOS专业版.
干杯
结果我将 SMTPClient 对象发送到另一个方法,然后尝试使用该对象发送邮件。这就是导致错误的原因,因为一旦该方法创建了自己的 SMTPClient 对象,它就停止抛出错误。
| 归档时间: |
|
| 查看次数: |
6919 次 |
| 最近记录: |