SocketException:没有这样的主机是已知的 - 无法发送电子邮件 - 统一

时间:2016-11-08 05:56:50

标签: c# unity3d smtp

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:没有这样的主机。

     

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

4 个答案:

答案 0 :(得分:2)

如果您从anroid设备发送,那么 我认为你有一段时间遇到同样的问题,请确保你的android版本要求获得Internet访问权限。

转到Android播放器设置,"其他设置"并寻找互联网接入。它" Auto"默认情况下,将其设置为"要求"。

答案 1 :(得分:0)

错误

  

SocketException:尚无此类主机。

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

由于代理服务器而发生。我的IP位于代理服务器之后,分配了直接Internet访问后,代码工作正常。

答案 2 :(得分:0)

SocketException:尚无此类主机。

解决方案:Internet无法执行该操作。检查您的互联网

答案 3 :(得分:0)

就我而言,这是我的互联网连接非常低。

相关问题