← All posts

2 Best Ways to Send Emails from Unity

· Updated July 14, 2026

UnityScriptingEmailsSMTP
Send emails from Unity

Introduction

Have you ever wanted to send emails from your Unity indie game? It’s easy. This tutorial covers the 2 best possible ways without using any third-party plugins to send emails from Unity. Many games from Unity use email features to improve their stability, robustness, and bug fixes.

During playing your game, users might want to send you a direct email to provide you with any feedback or suggestion. Most game developers want their users to see them in the portfolio and share their experience with the development team. It is also used to secretly record crash logs, error messages, or suspicious player activity.

Email is the best thing to share user experience with the development team. Now the question is how to send emails from Unity.

Displaying an email address to the user might not be the best way to encourage the user to send emails to the development team. This tutorial covers the 2 best possible ways including direct email using an SMTP server and using the default email application.

2 Best Ways to Send Emails

  1. Using default application
  2. Using SMTP server

Using Default Application

Here’s how you can do it by using the default email application on your mobile device.

  1. Create a script called MailSender.cs in your Unity project.
  2. Copy and paste the following code into the MailSender.cs class.
  3. Create a button in Unity and set it to click listener with the SendMail functions. Don’t forget to set your email address.
  4. Build and Run.
using UnityEngine.Networking;

public void SendEmail()
{
    string email = "MY EMAIL ADDRESS";
    string subject = MyEscapeURL("My Subject");
    string body = MyEscapeURL("My Body\r\nFull of non-escaped chars");
    Application.OpenURL("mailto:" + email + "?subject=" + subject + "&body=" + body);
}

string MyEscapeURL(string url)
{
    return UnityWebRequest.EscapeURL(url).Replace("+", "%20");
}

Updated for modern Unity: older versions of this tutorial (and most others you’ll find) use WWW.EscapeURL, but the WWW class has been deprecated for years. UnityWebRequest.EscapeURL is the current, supported equivalent.

Replace the email string with your actual email address. You can even collect more information on mobile devices using the SystemInfo class of Unity. Here is how you can do it in the body texts of your email.

// Body of the mail which consists of Device Model and its Operating System
string body = MyEscapeURL("Please Enter your message here\n\n\n\n" +
              "________" +
              "\n\nPlease Do Not Modify This\n\n" +
              "Model: " + SystemInfo.deviceModel + "\n\n" +
              "OS: " + SystemInfo.operatingSystem + "\n\n" +
              "________");

You can collect more data like battery information, memory information, graphics card information, processor information, and much more. This way of sending emails is exposing the data you collect to the user. Here is another way to send emails from the user’s mobile devices without exposing the data to the user.

Using SMTP Server

In this tutorial, we are using the Gmail SMTP server to send emails from Unity. Before going forward make sure of the following things,

  1. Enable 2-Step Verification on your Google account — App Passwords require it. (If you followed an older version of this tutorial: Google removed the “less secure app access” option entirely in 2024, so that route no longer exists.)
  2. Go to your Google account’s security page and open App Passwords
  3. Create a new app password for your game
  4. Store your newly created password safely
  5. Create a script called SmtpMailSender.cs
  6. Create a function inside the class called SendSmtpMail
  7. Copy and paste the following code into the SendSmtpMail function
  8. Resolve other library dependencies
MailMessage mail = new MailMessage();

mail.From = new MailAddress("Fromaddress@gmail.com");

mail.To.Add("Toaddress@gmail.com");

mail.Subject = "Test Smtp Mail";

mail.Body = "Testing SMTP mail from GMAIL";

// You can use others too.
SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");

smtpServer.Port = 587;

smtpServer.Credentials = new System.Net.NetworkCredential("youraddress@gmail.com", "yourpassword") as ICredentialsByHost;

smtpServer.EnableSsl = true;

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

try
{
    smtpServer.Send(mail);
}
catch (System.Exception e)
{
    Debug.Log("Email error: " + e.Message);
}
finally
{
    Debug.Log("Email sent!");
}

In the NetworkCredentials make sure you used your newly generated app password (not your regular Gmail password). Replace the required email address in the script with your actual email address.

Note: Set API Compatibility Level to ”.NET 2.0” and not ”.NET 2.0 Subset” in the build setting if you are using a Unity version less than 2017. Prior to Unity 2018 ”.NET 4.0” is the default. This method doesn’t work on WebGL games.

A word on security

Anything you ship inside a Unity build can be decompiled — including SMTP credentials. The SMTP approach is great for internal builds, prototypes, and QA tooling, but for a production game you should route the email through a small backend endpoint or a transactional email API, and keep the credentials on the server where players can’t extract them.

And if your needs grow beyond email — native share sheets, push notifications, or wrapping a platform SDK into Unity — that crosses into native plugin territory, which works quite differently from pure C# solutions. I’ve written a full guide on integrating native Android/iOS SDKs into Unity if that’s where you’re headed.