简体   繁体   中英

How can I send an email with a C# script in Unity?

I want to send an email with the results of a questionnaire when clicking a button but I have 0 experience with any method of sending an email. All the tutorials I found required you to download a library in Visual Studio and when I try to download them they just fail to download.

Try this

var fromEmail = "something@gmail.com";

var mail = new MailMessage();
mail.From = new MailAddress(fromEmail);
mail.To.Add("TO_EMAIL_ADDRESS");

mail.Subject = "EMAIL_SUBJECT";
mail.Body = "BODY_OF_EMAIL";

var smtpServer = new SmtpClient("smtp.gmail.com"); // Gmail smtp client
smtpServer.Port = 587; // Gmail smtp port

smtpServer.Credentials = new System.Net.NetworkCredential(fromEmail, "Password_of_from_email") as ICredentialsByHost;
smtpServer.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback =
delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{ 
    return true; 
};

smtpServer.Send(mail);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM