How to Send an Email or Text Message in C# with Unity

wolfs cry games
wolfs cry games
15.4 هزار بار بازدید - 5 سال پیش - In this video, I'll show
In this video, I'll show you how to send emails and text messages in your c# app with unity. You can do this on mobile or on PC with the exact same code. See below for referenced code. using UnityEngine; using UnityEngine.UI; using System.Net; using System.Net.Mail; using System.Net.Security; using System.Security.Cryptography.X509Certificates; public class EmailFactory : MonoBehaviour { public InputField bodyMessage; public InputField recipientEmail; public void SendEmail() { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); SmtpServer.Timeout = 10000; SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; SmtpServer.UseDefaultCredentials = false; SmtpServer.Port = 587; mail.From = new MailAddress("[email protected]"); mail.To.Add(new MailAddress(recipientEmail.text)); mail.Subject = "Test Email through C Sharp App"; mail.Body = bodyMessage.text; SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "MyPasswordGoesHere") as ICredentialsByHost; SmtpServer.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; SmtpServer.Send(mail); } public void SendText(string phoneNumber) { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); SmtpServer.Timeout = 10000; SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network; SmtpServer.UseDefaultCredentials = false; mail.From = new MailAddress("[email protected]"); mail.To.Add(new MailAddress(phoneNumber + "@txt.att.net"));//See carrier destinations below //message.To.Add(new MailAddress("[email protected]")); mail.To.Add(new MailAddress(phoneNumber + "@vtext.com")); mail.To.Add(new MailAddress(phoneNumber + "@messaging.sprintpcs.com")); mail.To.Add(new MailAddress(phoneNumber + "@tmomail.net")); mail.To.Add(new MailAddress(phoneNumber + "@vmobl.com")); mail.To.Add(new MailAddress(phoneNumber + "@messaging.nextel.com")); mail.To.Add(new MailAddress(phoneNumber + "@myboostmobile.com")); mail.To.Add(new MailAddress(phoneNumber + "@message.alltel.com")); mail.To.Add(new MailAddress(phoneNumber + "@mms.ee.co.uk")); mail.Subject = "Subject"; mail.Body = ""; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]", "MyPasswordGoesHere") as ICredentialsByHost; SmtpServer.EnableSsl = true; ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }; mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; SmtpServer.Send(mail); } }
5 سال پیش در تاریخ 1398/08/15 منتشر شده است.
15,464 بـار بازدید شده
... بیشتر