-1

I am working on a game and met with a roadblock. The game works fine. Whenever a player finishes the game, I want the score to be sent to my email address.

The game will be hosted on itch.io. The game lasts for 60 seconds, and then a Game Over panel comes up showing the user his score. At that point I want the score to be emailed to me as well. Is that possible? If not, any alternate way that can achieve my goal (to be able to see every user's score).

Thanks

  • [Unity WebGL Email](https://github.com/hendrik-schulte/unity-webgl-email) -> apparently it is possible yes ... – derHugo May 17 '21 at 16:00

1 Answers1

0

Sure, you should be able to use this code. Just create a file called SendEmail.cs and place it in your /Scripts folder. This assumes you are joker@gmail.com (password = justjokering) and sending the email to yourself. You can call it from another file, perhaps where you have the score variable computed using:

SendEmail.SendResults("joker@gmail.com","emailBodyText","emailSubjectText");

Here is the contents of the SendEmail.cs file:

using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
using System;
using System.Collections.Generic;

public class SendEmail : MonoBehaviour
{
    public string subject = "New Score Acquired";
    public string body = "putyourscoreASASTRINGhere";
    public string password = "";

    public void SendResults(string toAddress, string bodyText, string subjectText)
    {

        WriteDataFile(subjectText, bodyText);

        MailMessage mail = new MailMessage();

        mail.From = new MailAddress("joker@gmail.com");
        mail.To.Add(toAddress);
        mail.Subject = subjectText;
        mail.Body = bodyText;
        //var fileToAttach = GetComponent<realPicVerifApp>().logFilePathLocal;
        //mail.Attachments.Add(new Attachment(sshotlocation));
        SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
        smtpServer.Port = 587;
        smtpServer.Credentials = new System.Net.NetworkCredential("joker@gmail.com", "justjokering") as ICredentialsByHost;
        smtpServer.EnableSsl = true;
        ServicePointManager.ServerCertificateValidationCallback =
            delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            { return true; };
        smtpServer.Send(mail);
        Debug.Log("success");    
    }
}
Roger
  • 1