Ich versuche, eine E-Mail von innerhalb der Einheit auf Smartphones mit der SmtpClient-Klasse zu senden. Ich habe diese recht einfache Aufgabe auf iOS erreicht, aber der exakt gleiche Code funktioniert nicht auf Android. Hier ist der Code:Senden von E-Mails von innerhalb von unity3d
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;
}
Wo Absender, Passwort und Empfänger ist mein Google Mail-Konto, mein Google Mail-Passwort und die Person, die ich jeweils per E-Mail wünsche.
So funktioniert das perfekt auf iOS aber auf Android führt den folgenden Fehler:
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()
ich es geschafft haben, die Fehlerstelle in der Leitung pintpoint: smtpServer.Send(mail);
Irgendwelche Ideen, was verursachen könnte sein dieses Problem? Ich habe beide Android und iOS Pro-Versionen.
Prost
vielleicht ist es nicht auf der Suche nach einer E-Mail als Empfänger, sondern ein Name auf Ihrer Kontaktliste? Nur eine wilde Vermutung, aber Sie wissen nie. –