SocketException:没有这样的主机是已知的 – 无法发送电子邮件 – 统一
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)
如果你从anroid设备发送然后我认为你有一些相同的问题,请确保你的android版本要求Internet访问权限。
转到Android播放器设置,“其他设置”并查找Internet访问。 它默认为“自动”,将其设置为“需要”。