【发布时间】:2014-01-10 10:29:40
【问题描述】:
我正在尝试使用 SmtpClient 类从智能手机上的 unity 内部发送电子邮件。我在 iOS 上完成了这个非常简单的任务,但完全相同的代码在 android 上不起作用。代码如下:
private IEnumerator sendAutoMail (string textBody,string title)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress(sender);
mail.To.Add(receiver);
mail.Subject = "R4UL " + title;
mail.Body = textBody;
Debug.Log("Connecting to SMTP server");
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential(sender, password) as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
Debug.Log("Sending message");
smtpServer.Send(mail);
yield return null;
}
其中发件人、密码和收件人分别是我的 Gmail 帐户、我的 Gmail 密码和我希望发送电子邮件的人。
所以这在 iOS 上完美运行,但在 android 上会引发以下错误:
I/Unity (6256): SocketException: 没有这样的主机已知 I/Unity (6256): 在 System.Net.Dns.GetHostByName (System.String hostName) [0 x00000] in :0 I/Unity (6256 ): 在 System.Net.Dns.GetHostEntry (System.String hostNameOrAddress) [0x00000] in :0 I/Unity (6256): 在 System.Net.Dns.GetHostAddresses (System.String hostNameO rAddress) [0x00000] 在: 0 I/Unity(6256):在 System.Net.Sockets.TcpClient.Connect(System.String 主机名,Int32 端口)[0x00000] 在:0 I/Unity(6256):在 System.Net.Sockets.TcpClient。 .ctor(System.String 主机名,Int32 端口)[0x00000] 在:0 I/Unity(6256):在 System.Net.Mail.SmtpClient.SendInternal(System.Net.Mail .MailMessage 消息)[0x00000] 在: 0 I/Unity(6256):在 System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMessage 消息)[0x00000] 中:0 I/Unity(6256):作为 SmtpException 重新抛出:消息无法发送。 I/Unity (6256): 在 System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMes sage 消息) [0x00000] in :0 I/Unity (6256): 在 FeedbackSender+c__Iterator1.MoveNext ()
我已经设法查明了该行的错误位置:smtpServer.Send(mail);
关于可能导致此问题的任何想法?我有安卓和 iOS 专业版。
干杯
【问题讨论】:
-
也许它不是在寻找作为收件人的电子邮件,而是在您的联系人列表中寻找一个名字?只是一个疯狂的猜测,但你永远不会知道。