Error sending Email form the game, using SMTPClient Class

Works just fine in editor and standalone. I think also on android, but fails on IOS

This is the code
MailMessage mail = new MailMessage();
mail.From = new MailAddress(“”);
mail.Subject = “subject”;
mail.Body = “body”;

SmtpClient SmtpServer = new SmtpClient("");
SmtpServer.Port = 587;
SmtpServer.Credentials = new NetworkCredential("", "mypass") as ICredentialsByHost;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Timeout = 20000;
SmtpServer.EnableSsl = true;

ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };

I’ve tried to remove the validation callback, made sure my player settings API compatibility is set to .Net 2.0

still no luck/ any help please?

Using the SMTPClient class, I was able to send an email from unity using the following code:

using System.Net;
using System.Net.Mail;

using UnityEngine;

public class SendMail : MonoBehaviour {
    public string sender = "";
    public string receiver = "";
    public string smtpPassword = "mysmtppassword";
    public string smtpHost = "";

    // Use this for initialization
    private void Start() {
        using (var mail = new MailMessage {
            From = new MailAddress(sender),
            Subject = "test subject",
            Body = "Hello there!"
        }) {

            var smtpServer = new SmtpClient(smtpHost) {
                Port = 25,
                Credentials = (ICredentialsByHost)new NetworkCredential(sender, smtpPassword)
            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

The difference here is that I dissabled the SSL authentication bacause i simply didnt need it. My script here isnt as different to yours. Try to disable your SSL authentication and see what happens. Hope this helps :slight_smile:

Gmail accounts require SSL i’m afraid