获取“system.net.sockets.socketexception没有这样的主机是已知的”在Unity WebGL构建 [英] Getting "system.net.sockets.socketexception no such host is known" in Unity WebGL build

查看:1423
本文介绍了获取“system.net.sockets.socketexception没有这样的主机是已知的”在Unity WebGL构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我一直在Unity中的一个小型webgl事情上发送给用户,他们做了一些事情后的电子邮件。我收到了所有的建立,准备好去,但是当我建立它,并去测试它,当发送电子邮件时,我得到socketexception错误。



这是代码我正在使用电子邮件发送

  MailMessage mail = new MailMessage(); 
mail.From = new MailAddress(myEmail);
mail.To.Add(userEmail.text);
mail.Subject =感谢您在WilliamLeonSmith.com查看网络摄像头;
mail.Body =这是一个自动化的电子邮件,提供在WilliamLeonSmith.com创建的附加图像;

SmtpClient smtpServer = new SmtpClient(smtp.gmail.com);
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(myEmail,pass)as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
委托(对象s,X509证书证书,X509Chain链,SslPolicyErrors sslPolicyErrors)
{return true; };
smtpServer.Send(mail);


解决方案

不能 strong>套接字或 WebGL 上的任何其他.Net网络类。这是针对安全性的原因。虽然,您可以使用Unity的 WWW 类。



您还有两个其他选项。



[ EASY ]



1 php 中重写您在问题中的代码。使用Unity WWW 类将消息 toEmail,Subject,Body )发送到 php 脚本。 php 脚本然后发送实际电子邮件 / strong>它从 Unity应用程序收到。



如果您不要想学习 php ,您可以将编译您的问题中的代码作为控制台应用程序,然后将其用作 cgi 而不是 PHP 即可。 WWW class可以通过 php cgi 通过 GET POST 请求。



[ HARD ]



2 。您可以使用 UnitySocketIO 库实现 smtp协议或您自己的 MailMessage 类。 https://github.com/NetEase/UnitySocketIO


Hello and thank you for taking the time to look help me with my problem.

I have been working on a small webgl thing within Unity that will send the user an email after they have done some stuff. I got it all built and ready to go, however when I built it and went to test it I get the socketexception error, when sending the email.

Here is the code I am using to send the email

MailMessage mail = new MailMessage();
mail.From = new MailAddress(myEmail);
mail.To.Add(userEmail.text);
mail.Subject = "Thanks for viewing the Webcam page at WilliamLeonSmith.com";
mail.Body = "This is an automated email to deliver the attached images that were created at WilliamLeonSmith.com";

SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(myEmail, pass) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
                delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
                { return true; };
smtpServer.Send(mail);

解决方案

You cannot use Sockets or any other .Net network class on WebGL. This is for security reasons. Although, you can use Unity's WWW class.

You still have two Other Options.

[EASY]

1. Re-write the code you have in your question in php. Use Unity WWW class to send message(toEmail, Subject, Body) to the php script. The php script will then send the actually email with the information it received from the Unity App.

If you don't want to learn php,you can compile the code in your question as a console app and then use it as cgi instead of php. WWW class can communicate with both php or cgi programs through GET or POST request.

[HARD]

2. You can implement smtp protocol or your own MailMessage class with UnitySocketIO library. https://github.com/NetEase/UnitySocketIO

这篇关于获取“system.net.sockets.socketexception没有这样的主机是已知的”在Unity WebGL构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆