0

I am using Unity5 and writing some code to send a basic mail. I've read documentation as well as other users' problems, but can't seem to get my code to work properly. When I try to send the mail get this error : "InvalidOperationException: SSL authentication error: RemoteCertificateNotAvailable, RemoteCertificateChainErrors"

Here is my code so far, hope you guys got any advice ! :) Thanks.

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

    client.Send("MyMail", "MyPWD", "test", "testbody");
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Griga
  • 3
  • 2
  • Did you enable SMTP in your gmail account? I know that GMail has very specific requirements for third-parties to be able to send email via it. – Ruslan May 12 '15 at 13:53
  • Have you tried installing the remote certificate? See http://stackoverflow.com/questions/4148019/authentication-or-decryption-has-failed-when-sending-mail-to-gmail-using-ssl – chxzy May 12 '15 at 13:54

2 Answers2

0

This seems to work for me. I'd check your account if this doesn't work.

var smtp = new SmtpClient {
                Host = "smtp.gmail.com",
                Port = 587,
                EnableSsl = true,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials = new NetworkCredential("user", "password")
            };

            smtp.Send(message);
Josh
  • 10,352
  • 12
  • 58
  • 109
0

Based upon this Google SMTP settings page the ports are:

Port 465 (SSL required) Port 587 (TLS required)

So you want port 465 for SSL

Arkaine55
  • 548
  • 6
  • 15
  • Made Unity crash instantly : / – Griga May 12 '15 at 14:15
  • Setting a different port in your SmtpClient made Unity crash? That *sounds* more like a Unity problem than a .Net issue. Do you have any more details, like an error message or your machine ran out of memory? If you wrap your code snippet in a try{}catch{} and debug can you see a trapped error before it crashes (or prevent the crash?). As an alternative you could try testing your SMTP code in VisualStudio in a unit test project to make sure that is fine before seeing if the Unity editor can handle running it. – Arkaine55 May 12 '15 at 17:25
  • Is it possible your virus protection software is aggressively preventing unsigned applications from attempting to send emails: http://stackoverflow.com/questions/22702453/smtpclient-send-crashes-production-application – Arkaine55 May 12 '15 at 17:30