Playback starts YouTube’s embedded player (privacy-enhanced mode).
How to Send an Email or Text Message in C# with Unity
Channelwolfs cry gamesDescription from the creator
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);
}
}
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);
}
}
About this tutorial
wolfs cry games published this 16:43 video tutorial on November 28, 2019. It has been watched 16,305 times on YouTube.
- Channel
- wolfs cry games
- Category
- Gaming
- Duration
- 16:43
- Published
- November 28, 2019
- Views
- 16,305
- Likes
- 287
Share
This tutorial in other languages
- FRComment faire pour envoyer un message électronique ou Texte en C # avec Unity
- ESCómo enviar un correo electrónico o mensaje de texto en C # con Unity
- PTComo enviar um e-mail ou mensagem de texto em C # com Unity
- ITCome inviare una e-mail o messaggio di testo in C # con Unity
- DEWie E-Mail oder SMS-Nachricht in C # mit Unity senden
- NLHoe stel ik een e-mail of SMS-bericht in C # met Unity
- RUКак отправить по электронной почте или текстовое сообщение в C # с Unity
- PLJak wysłać e-mail lub wiadomość tekstową w języku C # z Unity
- JAどのようにUnityとC#に電子メールやテキストメッセージを送信するには
- ARكيفية إرسال البريد الإلكتروني أو رسالة نصية في C # مع الوحدة
- HIकैसे एकता के साथ सी # में एक ईमेल या पाठ संदेश भेजने के
- IDCara Kirim Email atau Pesan Teks di C # dengan Unity