SocketException:未知此类主机-无法发送电子邮件-统一 [英] SocketException: No such host is known - Failed to send email - unity

查看:84
本文介绍了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:尚无此类主机.

SocketException: No such host is known.

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

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

推荐答案

错误

SocketException:尚无此类主机.

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位于代理服务器后面,在分配了直接Internet访问后,代码可以正常工作.

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

这篇关于SocketException:未知此类主机-无法发送电子邮件-统一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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