- Home /
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 :)
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");
Comment
Answer by sas_88 · May 13, 2015 at 07:29 AM
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);
}
}
Thanks for your feedback ! This trick works fine but seems to bypass any SSL security so it might not be safe in the long run : /