how to send an email in unity C#

so, i looked around for a proper c# emailing script, it just needs to send text. And i could not find anything that sent the email, i am now stuck with this code:

using System;
using UnityEngine;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;


	public class mono_gmail : MonoBehaviour
	{
		public static void Main (string[] args)
		{
			MailMessage mail = new MailMessage();
			
			mail.From = new MailAddress("email@gmail.com");
			mail.To.Add("email@gmail.com");
			mail.Subject = "Test Mail";
			mail.Body = "This is for testing SMTP mail from GMAIL";
			
			SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
			smtpServer.Port = 465;
			smtpServer.Credentials = new System.Net.NetworkCredential("email@gmail.com", "password");
			smtpServer.EnableSsl = true;
			ServicePointManager.ServerCertificateValidationCallback = 
				delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
			{ return true; };
			smtpServer.Send(mail);
		}
	}

also, the email and password fields are filled in, but just not here for security purposes.

And i did the 465 port since that is the outgoing mail server port for ssl.

PS : nothing is printing errors either.

I hope you can help, thanks!

I faced these error while sending email from gmail, try sending by changing these two parameters:

         smtpServer.Port = 587;
         smtpServer.EnableSsl = true; // try toggling this value as well

and make sure the credentials are correct there shouldn’t be any encryption to the data when passing to smtp object.

Also, wrap your code in try-catch block to catch the exception message.

What if google doesn’t let me sign in? @NeverHopeless