Sending a mail : SSL authentication error

Hi everyone,

I am basically trying to send a mail from Unity, and I really don’t know why but I get an SSL authentication error when calling the function.
Here is my .NET code so far, would strongly appreciate any kind of advice :slight_smile:

var client = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587)
		{
			Credentials = (ICredentialsByHost)new System.Net.NetworkCredential("MyMail", "MyPWD"),
			EnableSsl = true
		};

		client.Send("MyMail", "MyMail", "test", "testbody");

Check with this

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

public class chkmail : MonoBehaviour 
{
	void Start ()
	{
		MailMessage mail = new MailMessage();

		mail.From = new MailAddress("youraddress@gmail.com");
		mail.To.Add("youraddress@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 = 587;
		smtpServer.Credentials = new System.Net.NetworkCredential("example@gmail.com", "example") as ICredentialsByHost;
		smtpServer.EnableSsl = true;
		ServicePointManager.ServerCertificateValidationCallback = 
			delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) 
		{ return true; };
		smtpServer.Send(mail);
	}
}