从unity3d内部发送电子邮件

 mobiledu2502897851 发布于 2023-02-04 17:11

我正在尝试使用SmtpClient类从智能手机内部发送一封电子邮件.我已经在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):at System.Net.Dns.GetHostEntry(System.String hostNameOrAdd ress)[0x00000] in:0 I/Unity(6256):at System.Net.Dns.GetHostAddresses(System.String hostNameO rAddress)[0x00000] in:0 I/Unity(6256):在System.Net.Sockets.TcpClient.Connect(System.String主机名,Int32端口)[0x00000] in:0 I/Unity(6256):at System.Net.Sockets.TcpClient..ctor( System.String hostna me,Int32 port)[0x00000] in:0 I/Unity(6256):at System.Net.Mail.SmtpClient.SendInternal(System.Net.Mail .MailMessage message)[0x00000] in:0 I/Unity(6256):在System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMes sage message)[0x00000] in:0 I/Unity(6256):Rethrow as SmtpException:无法发送消息.I/Unity(6256):在System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMes sage message)[0x00000] in:0 I/Unity(6256):在FeedbackSender + c__Iterator1.MoveNext()

我设法在线上找到错误位置: smtpServer.Send(mail);

关于可能导致这个问题的任何想法?我有Android和iOS专业版.

干杯

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有