从内unity3d发送电子邮件 [英] Sending email from inside unity3d

查看:1176
本文介绍了从内unity3d发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从内统一使用的SmtpClient类智能手机发送电子邮件。我已经实现了这个非常简单的任务,在iOS上,但完全相同的code不能在Android的工作。这里的code:

I am trying to send an email from inside unity on smartphones using the SmtpClient class. I have achieved this quite simple task on iOS but the exact same code does not work on android. Here's the code:

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密码和人,我想分别以发送电子邮件。

Where sender, password and receiver are my Gmail account, my Gmail password and the person I wish to email respectively.

所以这完美的作品在iOS,但Android上引发以下错误:

So this works perfectly on iOS but on android throws the following error:

I /统一(6256):SocketException:没有这样的主机被称为I /统一(6256):在System.Net.Dns.GetHostByName(System.String主机名)[0 X00000]:0 I /统一(6256 ):在System.Net.Dns.GetHostEntry(System.String hostNameOrAdd RESS)[0x00000]中:0 I /统一(6256):在System.Net.Dns.GetHostAddresses(System.String hostNameO rAddress)[0x00000]在: 0 I /统一(6256):在System.Net.Sockets.TcpClient.Connect(System.String主机名,端口的Int32)[0x00000]中:0 I /统一(6256):在System.Net.Sockets.TcpClient。 .ctor(System.String hostna我的Int32端口)[0x00000]中:0 I /统一(6256):在System.Net.Mail.SmtpClient.SendInternal(System.Net.Mail .MailMessage消息)[0x00000]在: 0 I /统一(6256):在System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMes圣人消息)[0x00000]中:0 I /统一(6256):重新抛出的SmtpException:邮件无法发送。 I /统一(6256):在System.Net.Mail.SmtpClient.Send(System.Net.Mail.MailMes圣人消息)[0x00000]中:0 I /统一(6256):在FeedbackSender + c__Iterator1.MoveNext()

I/Unity ( 6256): SocketException: No such host is known I/Unity ( 6256): at 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): at System.Net.Sockets.TcpClient.Connect (System.String host name, Int32 port) [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): at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMes sage message) [0x00000] in :0 I/Unity ( 6256): Rethrow as SmtpException: Message could not be sent. I/Unity ( 6256): at System.Net.Mail.SmtpClient.Send (System.Net.Mail.MailMes sage message) [0x00000] in :0 I/Unity ( 6256): at FeedbackSender+c__Iterator1.MoveNext ()

我已成功地pintpoint在该行的错误位置: smtpServer.Send(邮件);

I have managed to pintpoint the error location at the line: smtpServer.Send(mail);

任何想法,什么可能会造成这个问题?我同时拥有Android和iOS专业版。

Any ideas as to what might be causing this issue? I have both android and iOS pro versions.

干杯

推荐答案

原来我送SMTPClient对象到不同的方法,然后尝试使用对象发送邮件。这是因为它停止尽快抛出一个错误,因为该方法创建了自己的SMTPClient对象是什么原因导致的错误。

Turns out I was sending the SMTPClient object to a different method which was then trying to send a mail using that object. This is what was causing the error as it stopped throwing an error as soon as that method created its own SMTPClient object.

这篇关于从内unity3d发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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