Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Forked from marcotmp/UnityGMail.cs
Created August 28, 2025 10:04
Show Gist options
  • Save unitycoder/80cbcffcb722c13c29d2f696db63348d to your computer and use it in GitHub Desktop.
Save unitycoder/80cbcffcb722c13c29d2f696db63348d to your computer and use it in GitHub Desktop.

Revisions

  1. @marcotmp marcotmp revised this gist Apr 1, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion UnityGMail.cs
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,6 @@
    using System.Net.Mail;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    using UnityEngine;

    public class UnityGMail
    {
  2. @marcotmp marcotmp revised this gist Apr 1, 2022. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions UnityGMail.cs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,10 @@
    using System.ComponentModel;
    using System.Net;
    using System.Net.Mail;
    using System.Net.Security;
    using System.Security.Cryptography.X509Certificates;
    using UnityEngine;

    public class UnityGMail
    {
    public void SendMailFromGoogle()
  3. @marcotmp marcotmp revised this gist Apr 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion UnityGMail.cs
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    public class GMail
    public class UnityGMail
    {
    public void SendMailFromGoogle()
    {
  4. @marcotmp marcotmp revised this gist Apr 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion UnityGMail.cs
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ public void SendMailFromGoogle()
    smtp.Port = 587;

    // Account Username: Usually your "from" email.
    // App Password: If your app has a 2 step verification, you must follow these instructions
    // App Password: If your account has a 2 step verification, you must follow these instructions
    // to generate the password: https://support.google.com/accounts/answer/185833?hl=en.
    smtp.Credentials = new NetworkCredential("Account Username", "App Password") as ICredentialsByHost;
    smtp.EnableSsl = true;
  5. @marcotmp marcotmp renamed this gist Apr 1, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @marcotmp marcotmp created this gist Apr 1, 2022.
    29 changes: 29 additions & 0 deletions GMail.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    public class GMail
    {
    public void SendMailFromGoogle()
    {
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress("[email protected]");
    mail.To.Add("[email protected]");
    mail.Subject = "Email Subject";
    mail.Body = "Email Body";
    var attachment = new Attachment("C:\\path\\file.ext");
    mail.Attachments.Add(attachment);

    SmtpClient smtp = new SmtpClient("smtp.gmail.com");
    smtp.Port = 587;

    // Account Username: Usually your "from" email.
    // App Password: If your app has a 2 step verification, you must follow these instructions
    // to generate the password: https://support.google.com/accounts/answer/185833?hl=en.
    smtp.Credentials = new NetworkCredential("Account Username", "App Password") as ICredentialsByHost;
    smtp.EnableSsl = true;

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

    smtp.Send(mail);
    }
    }