HDTutorial
EN

Playback starts YouTube’s embedded player (privacy-enhanced mode).

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

16,305 views November 28, 2019 16:43

Watch on YouTube
Channelwolfs cry games

Description 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);
}
}

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.

Category
Gaming
Duration
16:43
Published
November 28, 2019
Views
16,305
Likes
287

Share

This tutorial in other languages