SocketException: No such host is known -发送邮件失败- unity

本文关键字:失败 unity -发 known No such host is SocketException | 更新日期: 2023-09-27 18:16:49

public void EmailSending() {
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress("xxx@gmail.com");
    mail.To.Add("xxx@gmail.com");
    mail.Subject = "Test Mail";
    mail.Body = "This is for testing SMTP mail from GMAIL";
    SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
    smtpServer.Port = 587;
    smtpServer.Credentials = new System.Net.NetworkCredential("xxx@gmail.com", "pw") as ICredentialsByHost;
    smtpServer.EnableSsl = true;
    ServicePointManager.ServerCertificateValidationCallback =
        delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        { return true; };
    smtpServer.Send(mail);
    Debug.Log("success");
}

我得到这个错误

SocketException: No such host is known.

System.Net.Dns。hostent_to_IPHostEntry(系统。字符串h_name,系统。String[] h_aliases, System。String [] h_addrlist)

SocketException: No such host is known -发送邮件失败- unity

如果您从非android设备发送的话我认为你有同样的问题的时候,确保你的android构建要求互联网访问权限。

进入Android播放器设置,"其他设置",寻找互联网接入。默认为"Auto",设置为"Require"

错误

SocketException: No such host is known.

System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist)

由于代理服务器而发生。我的IP在代理服务器后面,在分配直接互联网访问后,代码工作正常。

SocketException: No such host is known.

解决方法:网络不通,无法执行操作。查看你的网络

在我的情况下,这是我的网速很低。