SocketException: No such host is known - Failed to send email - unity

独自空忆成欢 提交于 2019-12-08 13:54:01

问题


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");
}

I am getting this error

SocketException: No such host is known.

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


回答1:


if you have sending from anroid device then I think you have same problem some time, make sure your android build asks for Internet Access permission.

Go to Android Player Settings, "Other settings" and look for Internet Access. It's "Auto" by default, set it to "Require".




回答2:


The error

SocketException: No such host is known.

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

was occurring due to proxy server. My IP was behind a proxy server, after assigning the direct internet access the code is working fine.



来源:https://stackoverflow.com/questions/40479951/socketexception-no-such-host-is-known-failed-to-send-email-unity

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!