Question by
Stanlyhalo · Nov 23, 2018 at 11:39 PM ·
c#systemhowemail
How to send email in c# in Unity 2018.2.17f1
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using UnityEngine.UI;
public class userSelectNav : MonoBehaviour {
public void sendMail()
{
try
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("senderEmail@gmail.com");
mail.To.Add("recieverEmail@gmail.com");
mail.Subject = "Test Subject";
mail.Body = "Test Body.";
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
smtpServer.Port = 587;
smtpServer.Credentials = new System.Net.NetworkCredential("senderEmail@gmail.com", "password") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
smtpServer.Send(mail);
Debug.Log("success");
}
catch (Exception ex)
{
Debug.Log(ex);
}
}
}
I got how to do this over at this link: https://answers.unity.com/questions/433283/how-to-send-email-with-c.html
Don't worry I got the one where people said this works, but it doesn't for me.
I can't show the error cus it's rlly long and I noticed it has my password in some areas.
Comment